Click here to Skip to main content
Click here to Skip to main content

Replacing the Default MFC Icon

, 16 Feb 2000
Rate this:
Please Sign up or sign in to vote.
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 resourc 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:
    ///////////////////////////////////////////////////////////////////////////// 
    
    //
    // 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:

    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: Its 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

About the Author

Shahzad Khan

United States United States
No Biography provided

Comments and Discussions

 
Questionvs2010 always Pinmembersteveh21125-Jul-11 17:53 
this is very frustrating. what even i do, edit the .ico file (in vs2010 or another editor), change to a new .ico file in resource editor, etc. vs2010 always puts the default MFC icons back in the .ico file so my changes are irrelevant.
 
i've tried a clean build, i've tried everything i can think of but nothing works.
 
any ideas please?
 
thanks
AnswerRe: vs2010 always [modified] Pinmembersteveh21125-Jul-11 18:09 
QuestionWhy the second icon not be changed? PinsussAnonymous25-Nov-04 23:21 
GeneralLoad Icon from a file PinmemberDosK19-Feb-03 23:12 
QuestionWhat when i have a multi document template and need different icons PinmemberAnup raje12-Oct-01 23:01 
AnswerRe: What when i have a multi document template and need different icons PinmemberAnonymous4-Jun-02 23:11 
GeneralThis always works... PinsussRoger C25-Sep-00 13:58 
Generalsimple solution! PinsussJarek31-Jul-00 15:22 
GeneralChange it by load a Icon-file PinsussWolfram Steinke25-Apr-00 19:07 
GeneralRe: Change it by load a Icon-file PinsussShahzad Alam Khan26-Apr-00 4:24 
GeneralRe: Change it by load a Icon-file PinsussPeter Lim3-Oct-00 15:04 
GeneralRe: Change it by load a Icon-file PinmemberAnonymous23-Nov-00 22:22 
GeneralRe: Change it by load a Icon-file PinmemberAnonymous28-Aug-01 4:47 
GeneralChange it by load a Icon-file PinsussStephan Strittmatter1-Mar-00 3:34 
GeneralRe: Change it by load a Icon-file PinsussShahzad Alam Khan2-Mar-00 3:24 
GeneralRe: Change it by load a Icon-file works! PinsussStephan Strittmatter2-Mar-00 21:16 
GeneralKia baat hai Shahzad ki PinsussAtif Anwar17-Feb-00 6:05 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 17 Feb 2000
Article Copyright 2000 by Shahzad Khan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid