How do you load an embedded icon from an exe file with PyWin32?

Efotinis: You're right. Here is a workaround until py2exe gets fixed and you don't want to include the same icon twice: hicon = win32gui. CreateIconFromResource(win32api.

LoadResource(None, win32con. RT_ICON, 1), True) Be aware that 1 is not the ID you gave the icon in setup. Py (which is the icon group ID), but the resource ID automatically assigned by py2exe to each icon in each icon group.At least that's how I understand it.

If you want to create an icon with a specified size (as CreateIconFromResource uses the system default icon size), you need to use CreateIconFromResourceEx, which isn't available via PyWin32: icon_res = win32api. LoadResource(None, win32con. RT_ICON, 1) hicon = ctypes.windll.

User32. CreateIconFromResourceEx(icon_res, len(icon_res), True, 0x00030000, 16, 16, win32con. LR_DEFAULTCOLOR).

Ah, yes. I forgot about that. Nice catch.

– efotinis Sep 22 '08 at 18:57.

If you're using wxPython, you can use the following simple code: wx. Icon(sys. Argv0, wx.

BITMAP_TYPE_ICO) I usually have code that checks whether it's running from an EXE or not, and acts accordingly: def get_app_icon(): if hasattr(sys, "frozen") and getattr(sys, "frozen") == "windows_exe": return wx. Icon(sys. Argv0, wx.

BITMAP_TYPE_ICO) else: return wx. Icon("gfx/myapp. Ico", wx.

BITMAP_TYPE_ICO).

Well, well... I installed py2exe and I think it's a bug. In py2exe_util. C they should init rt_icon_id to 1 instead of 0.

The way it is now, it's impossible to load the first format of the first icon using LoadIcon/LoadImage. I'll notify the developers about this if it's not already a known issue. A workaround, in the meantime, would be to include the same icon twice in your setup.Py: 'icon_resources': (1, 'my_icon.

Ico'), (2, 'my_icon. Ico') You can load the second one, while Windows will use the first one as the shell icon. Remember to use non-zero IDs though.

:).

You should set the icon ID to something other than 0: 'icon_resources': (42, 'my_icon. Ico') Windows resource IDs must be between 1 and 32767.

Sadly a higher ID doesn't work either. – Andreas Thomas Sep 18 '08 at 11:37.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions