Sign in to follow this  

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

This topic is 4022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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));

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:

Resource.rc

#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

This topic is 4022 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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