Miah-Avl
March 22nd, 2006, 05:47 PM
Hello,
I am writing a Win32 app which uses a tray icon, and I can get the icon to load using the LoadImage() function fine, but not with LoadIcon/MAKEINTRESOURCE().
I want to use LoadIcon because when I moved the app to another computer, the icon did not load in the tray. I think this is because with LoadImage, you must have to have the image on your machine, and with LoadIcon/MAKEINTRESOURCE it uses a resource so you don't? Let me know if I'm wrong there.
Anyway, it's about time for some code and an explanation:
void* icon = LoadImage(NULL, "icon2.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
HICON icon2 = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON2));
tray.cbSize = sizeof(tray);
tray.uID = 100;
tray.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
tray.hIcon = icon2; //TODO: Find out why this peice of poop won't work.
if(tray.hIcon == NULL)
{
MessageBox(NULL, "OMG, no icon!", "Fux0r3d!", MB_OK);
tray.hIcon = (HICON)icon;
}
tray.hWnd = wnd; // wnd is a function argument.
tray.uCallbackMessage = WM_USER;
strcpy(tray.szTip, tooltip); // Tooltip is a function argument.
Shell_NotifyIcon(NIM_ADD, &tray);
Okay, now for the explanation:
The above code is contained in a function, which takes an HWND paramater for the parent window, and a string for the tooltip. As you can see, I create an icon using two different methods, and fall back on the second when the first one fails (and fail it does). However, the second method works, and both use the same icon file.
In general, this may be because I'm having some sort of problem with MAKEINTRESOURCE(), because the second method will also fail if I attempt to load an image from a resource.
Thanks for any help anyone can provide.
I am writing a Win32 app which uses a tray icon, and I can get the icon to load using the LoadImage() function fine, but not with LoadIcon/MAKEINTRESOURCE().
I want to use LoadIcon because when I moved the app to another computer, the icon did not load in the tray. I think this is because with LoadImage, you must have to have the image on your machine, and with LoadIcon/MAKEINTRESOURCE it uses a resource so you don't? Let me know if I'm wrong there.
Anyway, it's about time for some code and an explanation:
void* icon = LoadImage(NULL, "icon2.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
HICON icon2 = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON2));
tray.cbSize = sizeof(tray);
tray.uID = 100;
tray.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE;
tray.hIcon = icon2; //TODO: Find out why this peice of poop won't work.
if(tray.hIcon == NULL)
{
MessageBox(NULL, "OMG, no icon!", "Fux0r3d!", MB_OK);
tray.hIcon = (HICON)icon;
}
tray.hWnd = wnd; // wnd is a function argument.
tray.uCallbackMessage = WM_USER;
strcpy(tray.szTip, tooltip); // Tooltip is a function argument.
Shell_NotifyIcon(NIM_ADD, &tray);
Okay, now for the explanation:
The above code is contained in a function, which takes an HWND paramater for the parent window, and a string for the tooltip. As you can see, I create an icon using two different methods, and fall back on the second when the first one fails (and fail it does). However, the second method works, and both use the same icon file.
In general, this may be because I'm having some sort of problem with MAKEINTRESOURCE(), because the second method will also fail if I attempt to load an image from a resource.
Thanks for any help anyone can provide.