Advertisement

Add an icon the the exe-file in Visual C++

Started by May 31, 2001 06:32 PM
11 comments, last by Andy Guts 23 years, 8 months ago
Hi, I would like some help on how to add an icon to my exe-file in Visual C++. I´ve heard that I have to include it in the resources options, but I have no idea on how to do this. Thanks for any help.
After opening your project, go to New->Files->Resource Script. Give it a name, location for the file, and make sure Add to Project is checked. Now, on the left side (or where ever you placed the workspace window). You should see a ResourceView tab (at the bottom most likely). Click on that. Right click on the upper most folder, and select Import. Select the file of the icon you''d like to add to your project and hit ok. Now, you can rename and edit the icon from the ___ Resources\Icon folder in the ResourceView.

For more information, tell use specifically what you want to do with the icon.

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/ (If my website isn''t down, it''s a miracle!)
Advertisement
OK, thanks.
Now I want the compiled .exe-file from this project to use the icon i put in resources instead of the default blue-white windows exe icon.
How do I do this?
In a Win32 Application you can do one of two things. One is to have them in the Window''s class when you create it:
  wcl.hIcon = LoadIcon(hThisInst, MAKEINTRESOURCE(MY_ICON));wcl.hIconSm = LoadIcon(hThisInst, MAKEINTRESOURCE(MY_ICON_SMALL));  

Or to send two messages telling it to change its icons:
  HICON hIcon = LoadIcon(hThisInst, MAKEINTRESOURCE(MY_ICON));HICON hIconSm = LoadIcon(hThisInst, MAKEINTRESOURCE(MY_ICON_SMALL));SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)hIcon);SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)hIconSm);  


Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/ (If my website isn''t down, it''s a miracle!)
Thanks for the help Null and void.
But could you (or someone else) be a little more indepht in how to do this. Which files do I need to include and what more code do I need?
It would be great if you could write all the code needed and where to put it (in the "main" class?).
Thanks.
That''s code that should fit right in with any project using the Win32 API. You aren''t doing a Console application, are you?

Resist Windows XP''s Invasive Production Activation Technology!
http://druidgames.cjb.net/ (If my website isn''t down, it''s a miracle!)
Advertisement
No, it´s not a console app.
I used your code (both examples) and got these errors:
wcl'' : missing storage-class or type specifiers
wcl'' : redefinition
''hwnd'' : undeclared identifier
''hIcon'' : undeclared identifier
''SendMessageA'' : missing storage-class or type specifiers
too many initializers (on sendmessage)
and so on...
What´s wrong..?
Firstly, is your app a "Win32 Application" or an MFC-based app? If it''s MFC, you''ll do things slightly differently.

The given code was not intended to be used literally, nor were you to use both snippets; they are both different and separate methods of accomplishing the same thing.

The first method is to set the icon when you register your window class and create your window. wcl is the WNDCLASS structure you have to fill in order to register a window class for your main window.

The second method...well, I would just use the first method.

If you need more info, let me know.
Thanks, I got it now.
Only one problem remaining, how do I declare the icon name?
I get the error "''MY_ICON_NAME'' : undeclared identifier".
Thanks!
Oops, i needed resources.h.
Now it compiles without any errors, but it still doesn´t use my icon.

anoying.

This topic is closed to new replies.

Advertisement