An MFC application always displays its own ICON for application and dialog. But while working for some products, we need to insert our own ICON, here I am going to describe that.
Using the Code
First of all, we need the new ICON. For inserting a new ICON, follow the below steps:
- Select "Icon" resource type and press "Import".
- Select your ICON file (*.ico) and open it.
- Now we have the new ICON in our work space
- The ICON of an MFC executable is the first ICON present in the application.
So, we need to set our ICON as the first ICON, we can set this in “Resource.h”.
Open Resource.h, it may be like this:
- Our next step is to change the ICON order as shown:
After you finish changing the application ICON, clean and rebuild your application and check your application ICON.
- Now we are going to change the dialog ICON. Open you application dialog class and go to
OnInitDialog() function and copy the below code at the bottom:
HICON hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON1));
You can also use a different ICON as dialog ICON.
- Jun-20-2012: First version