Sign in to follow this  

How to add an icon to Visual C++ Express application?

Recommended Posts

How to add (replace default) icon for native Win32 application written in Visual C++ 2005 Express? Please help.

Share this post

Link to post
Share on other sites
I don't know if the express edition have an easy of doing it, but you can do in code by changing couple lines when you register the window class.

You probably have something like this when you init your window:

int WINAPI WinMain( HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow)
winclass.lpfnWndProc = WindowProc;
winclass.cbClsExtra = 0;
winclass.cbWndExtra = 0;
winclass.hInstance = hinstance;
// This is the line you need to change.
winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
winclass.hCursor = LoadCursor(NULL, IDC_ARROW);
winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winclass.lpszMenuName = NULL;
winclass.lpszClassName = CLASSNAME;

Make your icon as a resource for the project, then change the IDI_APPLICATION to whatever the new icon ID is. Also you'll need to use MAKEINTRESOURCE on the ID to make it work. Something like:

winclass.hIcon = LoadIcon(NULL, MAKEINTRESOURCE(NEW_ICON_ID));

Share this post

Link to post
Share on other sites
Thanks, that was very useful, but I have found that some more steps are needed to do this task. VC Express does not support resource edititng, so we must create them in an external editor:


#define IDI_ICON1 101

IDI_ICON1 ICON "icon_name.ico"

Add this rc file and ico file to the project and then perform steps as previously described.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this