'ExtractIcon'에 해당되는 글 1건

  1. 2007/09/11 How to convert HIcon to TIcon ?
2007/09/11 07:51

How to convert HIcon to TIcon ?

Many Windows API functions return aHIcon value (handle to Icon). Here's how to "convert" a HIcon toTIcon (object)

For example, when usingExtractIcon to get icon from file, the resulting value is of the HICON type.

The answer is: Create a TIcon object and assign the handle received from the ExtractIcon function to the TIcon.Handle property. If you want a bitmap, create a TBitmap and draw the icon on the bitmap's canvas. Be sure to Free the TIcon object when no longer needed.

var
  MyIcon:TIcon;
  icoHandle: HIcon;
begin
  MyIcon:=TIcon.Create;
  try
  icoHandle := ExtractIcon(application.handle,'c:\windows\explorer.exe', 0) ;
  MyIcon.Handle:=icoHandle;
  Image1.Picture.Icon:=MyIcon;
  finally
  MyIcon.free;
  end;
end;
Trackback 0 Comment 0