Adding Icon Resource's

Started by
2 comments, last by Nokturnal 18 years, 10 months ago
Hi guys , i am having trouble adding icon resources to my program. The book i am following in trick's ... by andre lamothe. I am using vc++ 6.0 . I will just explain the steps i ve followed in adding the resources. insert->resource -icon - > imported the icon which was there in the same directory - saved the resource script. This resource script was not added to the project , so i had to add the file manually , the resource script and the header file generated in the appropriate folders. Expanded resource files -> the icon which i had imported had a default name , IDI_ICON1 so i changed it to IDI_MYICON In the IDE , opened resource.h and made hte following change :- #define IDI_MYICON 101 left the rest of the overhead intact. included the resource.h file in the main.cpp (which has winmain) #include "resource.h" made the fllowing changes to the code of window class wcx.hIconSm=LoadIcon(NULL,MAKEINTRESOURCE(IDI_MYICON)); wcx.hIcon=LoadIcon(NULL,MAKEINTRESOURCE(IDI_MYICON)); Now the thing displays a exclamation icon instead of the icon i ve chosen. Any suggestions to what i am doing wrong ??
"I think there is a world market for maybe five computers." -- Thomas Watson, Chairman of IBM, 1943
Advertisement
LoadIcon(NULL, xxx) loads a stock icon - where 101 appears to be the question mark - not icons that are stored in the resource file. To load your icon, you must pass a valid HINSTANCE. If you are loading an icon that is in your module resource, you can do:

LoadIcon(GetModuleHandle(NULL), xxxx);


HTH,
You're not passing in your instance handle, so Windows is loading it from the default icon library. Try LoadIcon(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_MYICON)) if you don't have direct access to your instance handle (as in WinMain).

edit: beaten >_<
Thanks , will try that out right now

edit :- Killer , works like a charm .

There is another thing i noticed , the Icon has two sizes 16 x 16 & 32 x 32 , the image which both project is different (I guess one if for hIcon and another for hIconSm ) on launching the application displayed the 16 x 16 image , and on launching it again it is displaying the 32 x 32 icon on the title bar & minimized , since both the lines on where i am assigning the icon resource are the same , when is the 16 x 16 displayed and when is the 32 x 32 displayed , is there a way to force either one of them to be displayed ?

thanks

[Edited by - Nokturnal on June 8, 2005 6:36:11 AM]
"I think there is a world market for maybe five computers." -- Thomas Watson, Chairman of IBM, 1943

This topic is closed to new replies.

Advertisement