Click to See Complete Forum and Search --> : problem using LoadIcon()


Rantic
March 17th, 2004, 09:59 AM
Im using notifyIconData to put an icon in the system tray. Im using LoadIcon() to pass the handle to the hIcon member of notifyIconData and i have my icon loaded as a resource IDI_ICON1. The problem is the icon dosnt appear but a blank space on the tray appears instead and i can click on the blank space to bring up my dialog ok, but i want the icon to display.

heres a code snippet :

notifyIconData.cbSize = sizeof( NOTIFYICONDATA ) ;
notifyIconData.hWnd = hwnd ;
notifyIconData.uID = TRAYICON_ID ;
notifyIconData.uFlags = NIF_MESSAGE | NIF_ICON

notifyIconData.hIcon= LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON1));

notifyIconData.uCallbackMessage = WM_TRAYICONMSG ;
Shell_NotifyIcon(NIM_ADD, &notifyIconData);

am i doing something wrong here? I cant understand why my icon wont display in the tray.

thanks,
r

RussG1
March 17th, 2004, 10:03 AM
Try using LoadImage instead of LoadIcon.
I am not sure why LoadIcon is not working for you, but using LoadImage as below works for me.
i.e.

notifyIconData.hIcon = (HICON)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);

RussG1
March 17th, 2004, 10:08 AM
If that doesn't work, then I would think that there is a problem with your icon itself.

RussG1
March 17th, 2004, 10:40 AM
BTW:
You may have noticed that the line:
------------
Shell_NotifyIcon(NIM_ADD, ¬ifyIconData);
------------
Got mangled when just posted your message as above.

To prevent that from happening, try to use the CODE tags when you post code. If you are not sure how to use them, just click on the CODE button, type a space and click OK and it will add the tags for you. Then just remove the space and put all your code in between the tags, and it will retain the formatting of your code.

Rantic
March 18th, 2004, 05:48 PM
thanks a mil RussG1 that LoadImage worked great!

also the code thing, i tried that it made no differnce that ¬ still appeared in place of the &.

thanks,
r