Win32 API Icon won't show on window?

I have a valid resource file, a valid icon, the icon is even attaching properly (Checked with Resource Editor) but for some reason only the EXE shows the icon, when the program is run, neither the tasbar icon, nor the window icon show the custom icon.

1
2
3
4
5
6
#define IDI_ICON 101
/**/
IDI_ICON ICON "icon.ico"
/**/
wc.hIcon=   LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON));
wc.hIconSm= (HICON)LoadImage(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON), IMAGE_ICON, 16, 16, 0);


And yes, both the RC and the CPP files have the header included.

MSVC++ 2008; Windows XP.

Thanks for the help!
Last edited on
Check this out: http://msdn.microsoft.com/en-us/library/ms648072(VS.85).aspx

Also this if the first one caught your interest: http://msdn.microsoft.com/en-us/library/ms683199(VS.85).aspx

It seems that if you pass an argument of "zero" or "NULL" to GetModuleHandle(...) it returns a handle to the program that called it. I'm pretty sure you want a handle to your resource file, but it has been a little while since I've done this.

EDIT: Sorry about the three or four edits I did on this, I kept miss reading the write up on the GetModuleHandle(...) function.
Last edited on
Upon further reading I see where you got confused. What you are trying to do here is load your icon as if it is a default Windows choice but it is not and #define ing it isn't going to change that, nice try though.

MSDN says you should be using the LoadImage(...) function anyway so if you're going to do it I would do it their way for now. http://msdn.microsoft.com/en-us/library/ms648045(VS.85).aspx

Try:
 
LoadImage(NULL, "icon.ico", IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);


Again, it's been a while since I've tried this but I'm going to go do that now. Thanks for the project :)
Last edited on
Okay, I had continued on with the tutorial ( http://www.winprog.org/tutorial/start.html ) I've been using, and odd things have happend, speficically what works in one program, isn't working in another.

On one program I have:
1
2
wc.hIcon=         LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));
wc.hIconSm=       LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON));


The resource file and header are basically the same (Except one has more stuff in it) In the newer file, it works, but in the file that this post was made for, it doesn't.

This is basically all my code on the one that doesn't work, and the one that does is derived from the same code: http://www.winprog.org/tutorial/resources.html
Last edited on
Found the issue! Apparently I need to pay more attention when copying code, as the issue was a second wc.hIconSm at the bottom of all the wc. code. However, that is there is the other programs that were working, so I know not why it only caused a problem in the one.
Nonetheless, problem solved!
Topic archived. No new replies allowed.