Somebody knows where I can find and example of API DrawIconEx.
I have a lot of large icons loaded at a TImagelist and I want use DrawIconEx
to draw "small versions" from these into a speedbutton or toolbutton
surface. (I believe that it's possible)
This message follows my original thread "How to display a small version of
an icon in SpeedButtons".
Thanks to Peter (TeamB) and Eddie Shipman for their posts.
Thanks in advance for your help.
Gustavo
procedure TForm1.Button1Click(Sender: TObject);
begin
LoadSPBTNGlyph('C:\Program Files\Paint Shop Pro 5\PSP.exe',SpeedButton1);
LoadSPBTNGlyph('C:\Program
Files\Borland\Delphi4\Bin\dbexplor.exe',SpeedButton2);
end;
procedure LoadSPBTNGlyph(FileName: String; SPBTN: TSpeedButton);
var
bmp1, bmp2: TBitmap;
ico1 : TIcon;
SmallIcon, LargeIcon: HIcon;
begin
bmp1 := TBitmap.Create;
bmp2 := TBitmap.Create;
ico1 := TIcon.Create;
ExtractIconEx(PChar(FileName), 0, LargeIcon, SmallIcon, 1);
ico1.Transparent := True;
ico1.Handle := SmallIcon;
bmp1.Width := 32;
bmp1.Height := 32;
bmp1.canvas.CopyMode := cmSrcCopy;
bmp1.Canvas.Draw(0,0, ico1 );
bmp2.Width := 16;
bmp2.Height := 16;
bmp2.canvas.CopyMode := cmSrcCopy;
bmp2.Canvas.StretchDraw(Rect(0, 0, 16, 16), bmp1 );
SPBTN.Glyph.Assign(bmp2);
ico1.Free;
bmp2.Free;
bmp1.Free;
end;
Gustavo Hurtado <hur...@mailbr.com.br> wrote in message
news:7mija9$34...@forums.borland.com...
procedure TForm1.FormPaint(Sender: TObject);
var
icon: TIcon;
begin
// draw 32*32 icon
imagelist1.draw( canvas, 10, 50, 0 );
icon := TIcon.Create;
try
imagelist1.geticon( 0, icon );
canvas.brush.color := color;
// draw same icon as 16*16
DrawIconEx( canvas.handle, 10, 90, icon.handle,
16, 16, 0, canvas.brush.handle, DI_MASK );
finally
icon.free
end;
end;
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Thanks Peter, thanks Eddie for your posts.
I developed a procedure that does exactly what Explorer does to draw small
versions from an large icon. The secret is use SHGetFileInfo API (WIN95) to
get a TRUE icon from file. If you load the icon in a TImageList it will
convert the icon into a bitmap and the result is a deformed image when using
DrawIconEx.
With a true icon just set the cxWidth and cyWidth parameters to 16 and
DrawIconEx will shrink the image like Explorer.
The only trouble is that the SHGetFileInfo function only works in WIN95 (It
will not generate an error when exe is running under NT, but it will display
cutted images).
I'm looking for an equivalent function that works in WinNT. Any help in this
research will be very welcome.
procedure TFormX.SetupToolbar;
var
i: Integer;
xPic : TPicture;
SFI : TSHFileInfo;
begin
{ I have a list of Icon Files in a stringlist - I know that it could be in
a RES file but I don't have the
knowledge, not yet... }
for i := 0 to FIconFiles.Count -1 do begin
try
xPic := TPicture.Create;
with xPic do begin
Bitmap.Height := 16;
Bitmap.Width := 16;
Bitmap.Canvas.Brush.Color := clBtnFace;
Bitmap.Canvas.FillRect(Rect(0, 0, Width, Height));
FillChar(SFI, SizeOf(SFI), 0);
if SHGetFileInfo(PChar(FIconFiles[i]), 0, SFI, SizeOf(SFI),
SHGFI_ICON or SHGFI_SMALLICON) <> 0
then begin
DrawIconEx(Bitmap.Canvas.Handle, 0, 0, SFI.hIcon, 16, 16, 0, 0,
DI_DEFAULTSIZE OR DI_NORMAL);
end;
ImgRes.Add(Bitmap, nil);
end;
finally
xPic.Free;
end;
end;
{ Setup toolbars }
TobA.Images := ImgRes;
end;
Gustavo Hurtado <hur...@mailbr.com.br> wrote in message
news:7mnc0j$7n...@forums.borland.com...
> Hi fellows !
>
> Thanks Peter, thanks Eddie for your posts.
>
<SNIP>
Yes, unfortunally I'm using D3. I know that SHGetFileInfo mapping is made
through ShellAPI unit so I will take a look at it's D4 version.
Regards,
Gustavo