Created
May 28, 2015 23:58
-
-
Save ethanhs/a83fe7ff7ea9b40c09af to your computer and use it in GitHub Desktop.
Get Icon for file (not working).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def geticon(PATH): | |
shfileinfostruct=SHFILEINFO() | |
SHGFI_ICON = 0x000000100 | |
SHGFI_DISPLAYNAME = 0x000000200 | |
SHGFI_TYPENAME = 0x000000400 | |
SHGFI_ATTRIBUTES = 0x000000800 | |
SHGFI_ICONLOCATION = 0x000001000 | |
SHGFI_EXETYPE = 0x000002000 | |
SHGFI_SYSICONINDEX = 0x000004000 | |
SHGFI_LINKOVERLAY = 0x000008000 | |
SHGFI_SELECTED = 0x000010000 | |
SHGFI_ATTR_SPECIFIED = 0x000020000 | |
SHGFI_LARGEICON = 0x000000000 | |
SHGFI_SMALLICON = 0x000000001 | |
SHGFI_OPENICON = 0x000000002 | |
SHGFI_SHELLICONSIZE = 0x000000004 | |
SHGFI_PIDL = 0x000000008 | |
SHGFI_USEFILEATTRIBUTES = 0x000000010 | |
SHIL_EXTRALARGE = 0x00002 | |
ret, info=shell.SHGetFileInfo(PATH,0,SHGFI_ICONLOCATION | SHGFI_ICON | SHGFI_SYSICONINDEX) | |
hIcon, iIcon, dwAttr, name, typeName = info | |
tempDirectory = os.getenv("temp") | |
ico_x = 256 | |
hdc = win32ui.CreateDCFromHandle( win32gui.GetDC(0) ) | |
hbmp = win32ui.CreateBitmap() | |
hbmp.CreateCompatibleBitmap(hdc, ico_x, ico_x) | |
hdc = hdc.CreateCompatibleDC() | |
hdc.SelectObject( hbmp ) | |
win32gui.DestroyIcon(hIcon) | |
SHIL_JUMBO = 0x000000004 | |
iidImageList=GUID("{46EB5926-582E-4017-9FDF-E8998DAA0950}") | |
hico=ctypes.c_void_p() | |
hres=ctypes.windll.shell32.SHGetImageList(SHIL_JUMBO,byref(iidImageList),hico) | |
#after here I know the code is wrong, I will change it to use DrawIconEx or something like that. | |
hdc.DrawIcon( (0,0), hico ) | |
hbmp.SaveBitmapFile( hdc, tempDirectory + "\Icontemp.bmp") | |
icon=Image.open(tempDirectory+"\Icontemp.bmp") | |
os.remove(tempDirectory+"\Icontemp.bmp") | |
return icon |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment