Click here to Skip to main content
15,892,643 members
Articles / Multimedia / GDI

Replacing the Default MFC Icon

Rate me:
Please Sign up or sign in to vote.
3.32/5 (9 votes)
16 Feb 2000 163.5K   25   18
How to replace the default MFC icon in your application

Many fresh MFC programmers wonder how to 'replace' the default icon rather than to change or edit in the resource editor. Here are two simple ways to do this (actually one method but two versions).

  1. There is an ICON statement in the resource (.rc) file that causes the resource compiler to include the icon in the program's resources. The default icons for MFC projects are placed in ../res folder. To replace these icons, we need to edit rc file and supply new icons for the existing ones. Proceed as follows:
    1. Copy the new icon file in .../res folder. This step is not essential but its better to put all the resources in one folder.
    2. Select File -> Open and File Open Dialog popups. Select the .rc file and change the 'open as' combo box to 'text' (which is 'auto' by default) in the File -> Open Dialog box. Now Look for the ICON statement in the .rc file, which should look like:
    C++
    ///////////////////////////////////////////////////////////////////////////// 
    
    //
    // Icon 
    //
    // Icon with lowest ID value placed first to ensure application icon
    // remains consistent on all systems.
    
    IDR_MAINFRAME           ICON    DISCARDABLE     "res\\Project.ico"
    IDR_DEVICETYPE          ICON    DISCARDABLE     "res\\ProjectDoc.ico"

    Next, simply change the concerned file name with new one, e.g.:

    C++
    IDR_MAINFRAME           ICON    DISCARDABLE     "res\\NewIcon.ico"

    Now build the project and the new icon should show up.

  2. The second way is the short-cut version of the first. Instead of editing the .rc file, just rename the new icon to the same old icon name and copy onto it. However, if you build your project, the same old (default) icon will be shown though it does not even exist on the disk now! This is because the resource compiler does not detect any changes in rc file and hence it doesn't actually recompile the .rc file (unless some change is introduced into it). As a result, the program shows the same old icon which was added to it in the last compilation. Hence to take the effect, just recompile the rc file. It can simply be done by opening it as a text file (as in method 1), click in the file and compile (Ctrl+F7).

Note: It's generally not recommended to manually edit .rc file, however there is no harm with the above procedures and can be used without any fear.

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.


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questionvs2010 always Pin
steveh21125-Jul-11 17:53
steveh21125-Jul-11 17:53 
AnswerRe: vs2010 always [modified] Pin
steveh21125-Jul-11 18:09
steveh21125-Jul-11 18:09 
Question#if way? Pin
Super Garrison6-Aug-08 7:13
Super Garrison6-Aug-08 7:13 
QuestionWhy the second icon not be changed? Pin
Anonymous25-Nov-04 23:21
Anonymous25-Nov-04 23:21 
GeneralLoad Icon from a file Pin
BRWX19-Feb-03 23:12
BRWX19-Feb-03 23:12 
QuestionWhat when i have a multi document template and need different icons Pin
12-Oct-01 23:01
suss12-Oct-01 23:01 
AnswerRe: What when i have a multi document template and need different icons Pin
4-Jun-02 23:11
suss4-Jun-02 23:11 
GeneralThis always works... Pin
Roger Scudder25-Sep-00 13:58
Roger Scudder25-Sep-00 13:58 
Generalsimple solution! Pin
jarek31-Jul-00 15:22
jarek31-Jul-00 15:22 
GeneralChange it by load a Icon-file Pin
Wolfram Steinke25-Apr-00 19:07
Wolfram Steinke25-Apr-00 19:07 
GeneralRe: Change it by load a Icon-file Pin
Shahzad Alam Khan26-Apr-00 4:24
sussShahzad Alam Khan26-Apr-00 4:24 
GeneralRe: Change it by load a Icon-file Pin
Peter Lim3-Oct-00 15:04
Peter Lim3-Oct-00 15:04 
GeneralRe: Change it by load a Icon-file Pin
23-Nov-00 22:22
suss23-Nov-00 22:22 
Sounds to me that you changed the Icon bij changing the iconbitmap manualy. But you only changed the 32x32 Icon, but didn't change the 16x16 Icon of IDR_MAINFRAME.
This 16x16 Icon (when present) is shown in the upper left corner. If it's not available then windows calculates it from the 32x32 Icon.
GeneralRe: Change it by load a Icon-file Pin
28-Aug-01 4:47
suss28-Aug-01 4:47 
GeneralChange it by load a Icon-file Pin
Stephan Strittmatter1-Mar-00 3:34
Stephan Strittmatter1-Mar-00 3:34 
GeneralRe: Change it by load a Icon-file Pin
Shahzad Alam Khan2-Mar-00 3:24
sussShahzad Alam Khan2-Mar-00 3:24 
GeneralRe: Change it by load a Icon-file works! Pin
Stephan Strittmatter2-Mar-00 21:16
Stephan Strittmatter2-Mar-00 21:16 
GeneralKia baat hai Shahzad ki Pin
Atif Anwar17-Feb-00 6:05
sussAtif Anwar17-Feb-00 6:05 

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.