Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Change ICON of MFC Application and Dialog

0.00/5 (No votes)
19 Jun 2012 4  
Change the default ICON of MFC applications

Introduction

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:

  1. Select "Icon" resource type and press "Import".

  2. Select your ICON file (*.ico) and open it.

  3. Now we have the new ICON in our work space IDI_ICON1.

  4. 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:

  5. 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.

  6. 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:
    BOOL CtestlibDlg::OnInitDialog()
    {
    …………
    HICON hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON1));
    SetIcon(hIcon, FALSE)
    return TRUE;  // return TRUE  unless you set the focus to a control
    }

    You can also use a different ICON as dialog ICON.

History

  • Jun-20-2012: First version

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here