Reputation: 1765
So I have a program which doesn't have a console. It starts up by making a dummy HWND which it then hides and then acts as a notification area application (stays in tray). People can hover over the program to view its status and press hotkeys to perform tasks on screen.
Anyway, I want to display my programs icon in the tray but cannot. I added the icon resource to Visual studio and my executable has an icon in explorer. The resource has sizes from 16x16 - 256x256.
Now, I set NOTIFYICONDATA's info to: nid.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_ICON1));
and included "resource.h"
Which defines IDI_ICON1 as 104. However when I use this the blue explanation point icon shows up (ie one of the windows default ones). I tried IDI_ERROR and the error icon showed up fine. I tried a custom 12x12 icon as I read size may be the issue but that didnt work either.
IDI_APPLICATION uses the default icon for the application, ie the default .exe icon.
I currently don't know what to try or do.
Thanks in advance for your help!
Upvotes: 1
Views: 1312
Reputation: 3049
An MSDN article for LoadIcon() says this about its first argument:
A handle to an instance of the module whose executable file contains the icon to be loaded. This parameter must be NULL when a standard icon is being loaded.
Since you're not loading the standard icon, but your own, you need to provide a valid module handle. The module handle for your executable could be retrieved with passing NULL
to GetModuleHandle() function, so the code would look like this:
nid.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
Upvotes: 5