[python-win32] Extract icon from exe files

Tim Roberts timr at probo.com
Tue Apr 21 01:37:22 CEST 2009


EISEN Nicolas wrote:
> Hi,
>
> After search, I found many function to get Handler from exe (or dll)
> file icons . But I don’t understand how use the Handler …
>
> For example:
>
> />>> Import win32gui
>> >> i= win32gui.ExtractIcon(0,'e:\\dxdiag.exe',0)
>> >> icon = win32gui.LoadIcon ( i , 0)/
>
>
> Or with ExtractIconEx to get a list of all icons, I’m always with many
> Handlers without knowing how to save or write it in file.
>
> The finality is to extract the exe file icon, and next, save the
> picture on the disk.

Why do you want to do this?  Icons are intellectual property.  Unless
it's an open source app, you can't just scrape a bunch of icons from
existing applications and gather them into a library.  It's not legal.

Having said that, a few minutes with Google and MSDN would have answered
this question.  LoadIcon returns an HICON.  You can pass that to
GetIconInfo to return an ICONINFO structure, which includes the two
bitmaps that you need to draw an icon.  An icon always includes two
bitmaps: one is a monochrome bitmap that digs the hole for the color
image, and the other is the color image.  Those are HBITMAP handles. 
You can then use GetBitmapBits to get the actual pixels.

It's possible this might be easier in C.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list