I am able to get icons from non-UWP apps with the following code:
from win32con GCL_HICON, WM_GETICON,
from win32gui import GetClassLong, SendMessageTimeout
_, icon_handle = SendMessageTimeout(hwnd, WM_GETICON, 1, 0, 0, 50)
if icon_handle == 0:
icon_handle = GetClassLong(hwnd, GCL_HICON)
if icon_handle == 0:
return Settings.BLANK_ICON
Documentation says that the next step should be using LoadIcon/LoadImage to extract it from the executable, but I've tried to avoid that.
SO post says UWP app icon path could be retrieved by SHLoadIndirectString (ctypes.windll.shlwapi.SHLoadIndirectString from Python), but that topic deals with the files associations found in the registry - an open window isn't the starting point.
How can I retrieve that "indirect string" having just a window handle? Or maybe someone knows about some other solution to this problem, I'm interested in any type of icon/image I can get.
EDIT: accepted answer together with this answer reveals a way to solve this with Python and ctypes.