- Code: Select all
unit HImageList;
interface
uses
Windows, Messages, SysUtils, Classes, ImgList, Controls, Graphics,
HColorUtitles, CommCtrl;
type
THImageList = class(TImageList)
private
{ Private declarations }
protected
procedure DoDraw(Index: Integer; Canvas: TCanvas; X, Y: Integer;
Style: Cardinal; Enabled: Boolean = True);override;
public
{ Public declarations }
published
{ Published declarations }
end;
procedure Register;
implementation
{$R *.dcr}
procedure Register;
begin
RegisterComponents('HAKGERSoft Components', [THImageList]);
end;
//Special constans
const
DrawingStyles: array[TDrawingStyle] of Longint = (ILD_FOCUS, ILD_SELECTED,
ILD_NORMAL, ILD_TRANSPARENT);
Images: array[TImageType] of Longint = (0, ILD_MASK);
//functions needed
function GetRGBColor(Value: TColor): DWORD;
begin
Result := ColorToRGB(Value);
case Result of
clNone: Result := CLR_NONE;
clDefault: Result := CLR_DEFAULT;
end;
end;
function GetColor(Value: DWORD): TColor;
begin
case Value of
CLR_NONE: Result := clNone;
CLR_DEFAULT: Result := clDefault;
else
Result := TColor(Value);
end;
end;
{ THImageList }
procedure THImageList.DoDraw(Index: Integer; Canvas: TCanvas; X,
Y: Integer; Style: Cardinal; Enabled: Boolean);
type
pRGBTripleArray=^TRGBTripleArray;
TRGBTripleArray=array [Word] of TRGBTriple;
function CompareRGB(RGB1: TRGBTriple; RGB2: TRGBTriple): Boolean;
begin
Result:=(RGB1.rgbtBlue=RGB2.rgbtBlue) and (RGB1.rgbtGreen=RGB2.rgbtGreen)
and (RGB1.rgbtRed=RGB2.rgbtRed);
end;
const
ROP_DSPDxax = $00E20746;
var
FBitmap: TBitmap;
Row: pRGBTripleArray;
rX, rY: Integer;
RGB, RGBTransparent: TRGBTriple;
begin
if Enabled then
begin
inherited;
Exit;
end
else
begin
if HandleAllocated then
begin
FBitmap:=TBitmap.Create;
With FBitmap do
begin
Width:=Self.Width;
Height:=Self.Height;
PixelFormat:=pf24Bit;
end;
FBitmap.Canvas.Brush.Color := clWhite;
FBitmap.Canvas.FillRect(Rect(0, 0, Self.Width, Self.Height));
ImageList_DrawEx(Handle, Index, FBitmap.Canvas.Handle, 0,0,0,0,
CLR_NONE, 0, ILD_NORMAL);
for rY:=0 to FBitmap.Height-1 do
begin
Row:=FBitmap.ScanLine[rY];
for rX:=0 to FBitmap.Width-1 do
begin
If (rX=0) and (rY=0) then
begin
RGBtransparent:=Row[rX];
Continue;
end;
RGB:=Row[rX];
If CompareRGB(RGB, RGBTransparent) then
Continue;
Row[X].rgbtBlue:=RGBToLightness(RGB.rgbtRed, RGB.rgbtGreen, RGB.rgbtBlue);
Row[X].rgbtGreen:=RGBToLightness(RGB.rgbtRed, RGB.rgbtGreen, RGB.rgbtBlue);
Row[X].rgbtRed:=RGBToLightness(RGB.rgbtRed, RGB.rgbtGreen, RGB.rgbtBlue);
end;
end;
Canvas.Draw(X, Y, FBitmap);
end;
end;
end;
end.
It draws bitmap, but not in color I Want, and also when bitmap is in TMenuItem, when Menuitem is selected, then funny thing happends:
What I Do wrong?