[PyQt] Paint icon extracted from an execuatable?

Christopher Poole chrstphrpoole91 at gmail.com
Wed Oct 21 18:22:58 BST 2009


What would be the best way to extract an icon from an executable and paint
it to the screen using the QPainter?
Is there anything in PyQt that would let me open say C:\Program
Files\Mozilla Firefox\Firefox.exe and extract its icon? I know that you can
use win32gui to extract icons and save them as a .bmp

Quick example of that would be:
import win32ui
import win32gui
import win32con
import win32api

ico_x = win32api.GetSystemMetrics(win32con.SM_CXICON)
ico_y = win32api.GetSystemMetrics(win32con.SM_CYICON)

large, small = win32gui.ExtractIconEx("C:/Program Files/Mozilla
Firefox/Firefox.exe",0)
win32gui.DestroyIcon(large[0])

hdc = win32ui.CreateDCFromHandle( win32gui.GetDC(0) )
hbmp = win32ui.CreateBitmap()
hbmp.CreateCompatibleBitmap( hdc, ico_x, ico_x )
hdc = hdc.CreateCompatibleDC()

hdc.SelectObject( hbmp )
hdc.DrawIcon( (0,0), small[0] )
hbmp.SaveBitmapFile( hdc, "save.bmp" )

Only problem with this is it saves a bmp where I want to paint the icon
using QPainter, this also does not product a transparent icon. Is there any
quick way to extract the icon using PyQt?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20091021/e036a59c/attachment.html


More information about the PyQt mailing list