Tray icon, not displaying?

Hi
I have a little problem with my tray icon, I fill the NOTIFYICONDATA struct with all the information I need and use Shell_NotifyIcon() to add a icon to tray.

The thing is that it works fine in a another editor and I tried various combos now...

Loading the icon from a file works, but I don't want that.. :
1
2
HICON HIcon = (HICON)LoadImage(0,"RES\\ico.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
nid.hIcon = HIcon;

Loading it from a source works in devc++ but not vc++:
1
2
3
4
HICON hIcon = (HICON)LoadImage( GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);
nid.hIcon = hIcon;
or
nid.hIcon = (HICON)LoadImage( GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 32, 32, 0);


LoadIconMetric() and LoadIcon() doesnt work nether, what am i doing wrong?
This is going to sound extremely pedantic but have you included the .RC file in your project?

Also, for line 4 of your code, you should be freeing the allocated handle with DestroyIcon.
Yes, the .rc is in my project, the icon works for my main window and the small icon down at the sysbar...

And the tray icon works fine when i use devc++ :/ but not vc++

EDIT: I found one way of doing it, hopefully its right
1
2
3
4
5
6
7
8
9
10
11
12
HICON hicon; // Global

In winmain():
hicon=LoadIcon(hThisInstance,MAKEINTRESOURCE(IDI_ICON));
wincl.hIcon = CopyIcon(hicon);
wincl.hIconSm = CopyIcon(hicon);

Using it with NOTIFYICONDATA:
nid.hIcon = CopyIcon(hicon);

In WM_DESTROY:
DestroyIcon(hicon);
Last edited on
Topic archived. No new replies allowed.