If I don\'t use WM_SETICON first to set the icon then WM_GETICON is always returning 0. This is weird. Please help.
This is my code, can copy paste into scratchpad and r
Since you got the WM_GETICON
stuff from me (in another answer to another question) let me first say: It has been a while... So I forgot that WM_GETICON
will return null when the window has no particular window icon assigned, but instead the icon is taken from the registered window class.
So you should:
WM_GETICON
to see if the window has a specific icon assigned.GetClassLongPtr(hwnd, GCLP_HICON /* or GCLP_HICONSM */)
.exe
Here is some C++ code which I use to actually get an icon from a window in my "mintrayr" extension:
// Get the window icon
HICON icon = reinterpret_cast(::SendMessageW(hwnd, WM_GETICON, ICON_SMALL, 0));
if (icon == 0) {
// Alternative method. Get from the window class
icon = reinterpret_cast(::GetClassLongPtrW(hwnd, GCLP_HICONSM));
}
// Alternative method: get the first icon from the main module (executable image of the process)
if (icon == 0) {
icon = ::LoadIcon(GetModuleHandleW(0), MAKEINTRESOURCE(0));
}
// Alternative method. Use OS default icon
if (icon == 0) {
icon = ::LoadIcon(0, IDI_APPLICATION);
}