Click here to Skip to main content
15,885,985 members
Articles / Desktop Programming / MFC
Tip/Trick

Change ICON of MFC Application and Dialog

Rate me:
Please Sign up or sign in to vote.
4.81/5 (10 votes)
19 Jun 2012CPOL 83.3K   1   3
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. Image 1

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

    Image 2

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

    Image 3

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

    Image 4

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

    Image 5

  6. Our next step is to change the ICON order as shown:

    Image 6

    After you finish changing the application ICON, clean and rebuild your application and check your application ICON.

  7. 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:
    C++
    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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionAfxGetInstanceHandle() doesnot work for my project Dialog Pin
Member 1447449329-May-19 3:25
Member 1447449329-May-19 3:25 
QuestionUnnecessary! Pin
chaau19-Jun-12 19:52
chaau19-Jun-12 19:52 
AnswerRe: Unnecessary! Pin
Binu MD19-Jun-12 20:10
Binu MD19-Jun-12 20:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.