Click here to Skip to main content
13,142,707 members (55,218 online)
Click here to Skip to main content
Add your own
alternative version

Stats

42.9K views
1 bookmarked
Posted 19 Jun 2012

Change ICON of MFC Application and Dialog

, 19 Jun 2012
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Binu MD
Software Developer (Senior)
India India
No Biography provided

You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionUnnecessary! Pin
chaau19-Jun-12 19:52
memberchaau19-Jun-12 19:52 
AnswerRe: Unnecessary! Pin
Binu MD19-Jun-12 20:10
memberBinu 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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170915.1 | Last Updated 20 Jun 2012
Article Copyright 2012 by Binu MD
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid