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

Started by
3 comments, last by Paulius Maruska 17 years, 4 months ago
How to add (replace default) icon for native Win32 application written in Visual C++ 2005 Express? Please help.
Advertisement
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){	WNDCLASS winclass;	winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;	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));

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:

Resource.rc
#define IDI_ICON1 101IDI_ICON1 ICON "icon_name.ico"


Add this rc file and ico file to the project and then perform steps as previously described.
I highly recommend this.
Quote:Original post by Funkymunky
I highly recommend this.

OMG, dude. All this time I was writing my resource scripts by hand... Thank you for this link! :)

This topic is closed to new replies.

Advertisement