[python-win32] Extract icon from exe files

EISEN Nicolas neisen at linbox.com
Tue Apr 28 17:08:28 CEST 2009


Tim Roberts wrote:
> EISEN Nicolas wrote:
>   
>>>   
>>>       
>>   / from win32gui import *
>>    import win32con
>>
>>    listHicon = ExtractIconEx("c:\OpenOffice.exe",0)
>>
>>    test =
>> LoadImage(listHicon[0],"c:\OpenOffice.exe",0,0,0,win32con.LR_DEFAULTSIZE)  
>>  
>>      tupleIcon = GetIconInfo(test)/
>>
>> To use GetIconInfo argument should be pyHandle. listHicon is array of
>> Hicon. LoadImage return Handle, but the last argument must be an pyHandle
>> (by the interpretor error)
>>     
>
>    import pywintypes
>    ph = pywintypes.HANDLE( listHicon[0] )
>
> Now you have a PyHANDLE.
>
>
>   
>> PS : the demo menu and taskbar use icon only to display it in another
>> module, but i want get bitmapBit of icon to send it to an inventory
>> server.
>>     
>
> The demo fetches the icon and then uses BitBlt to draw it to a bitmap. 
> Why is that not EXACTLY what you need?  That saves you all the trouble
> of trying to extract the bitmaps from the icon and manipulate them in
> somewhat to get a usable image.
>
>   
I'm lucky, I found ...

My Source :

   /from win32gui import *
   import win32con
   from pywintypes import HANDLE
    import win32ui  

   listHicon = ExtractIconEx("c:\OpenOffice.exe",0)
   tupleIcon = GetIconInfo (HANDLE ( listHicon[0][0] ) )

   bitmapColor = tupel [4]

    picture = win32ui.CreateBitmap()
   buffer = picture.GetBitmapBits ( bitmapColor )
/


Python return :
/win32ui.error: GetObject failed on bitmap/
for the last line


win32ui have CreateBitmap with 0 argument and GetBitmapBits with 1 arguments
but win32gui have CreateBitmap with 5 arguments and GetBitmapBits have 2 
arguments

With win32gui, the two last line will be :

   / picture = CreateBitmap(tupel[1],tupel[2],1, 256, None)
    buffer = picture.GetBitmapBits( bitmapColor, 32)
/
but picture will be an pyHANDLE and i can't use GetBitmapBits ...


I need take Stringbit for write it on file to display on the website 
(bmp, jpeg, ...).


On the demo, hicon is use ton create the variable nid and re use it to 
display on the screen, but i want get only the bitmap bits.


Thanks


More information about the python-win32 mailing list