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<HICON>(::SendMessageW(hwnd, WM_GETICON, ICON_SMALL, 0));
if (icon == 0) {
// Alternative method. Get from the window class
icon = reinterpret_cast<HICON>(::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);
}
Well, there is a surprisingly easy (and cross-platform) way to retrieve the default icon of Firefox.
var foxexe = FileUtils.getFile("XREExeF", []);
var iconurl = "moz-icon:" + Services.io.newFileURI(foxexe).spec;
You can treat iconurl
the same way as any other image-pointing url. The default size is 16x16, append ?size=32
to get a bigger icon. It seems that these two values are the only supported on Windows. This might not be the case for other OSes.