Click here to Skip to main content
Licence 
First Posted 16 Feb 2000
Views 113,735
Bookmarked 24 times

Replacing the Default MFC Icon

By | 16 Feb 2000 | Article
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

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionvs2010 always Pinmembersteveh211217:53 5 Jul '11  
AnswerRe: vs2010 always [modified] Pinmembersteveh211218:09 5 Jul '11  
Question#if way? PinmemberSuper Garrison7:13 6 Aug '08  
QuestionWhy the second icon not be changed? PinsussAnonymous23:21 25 Nov '04  
GeneralLoad Icon from a file PinmemberDosK23:12 19 Feb '03  
QuestionWhat when i have a multi document template and need different icons PinmemberAnup raje23:01 12 Oct '01  
AnswerRe: What when i have a multi document template and need different icons PinmemberAnonymous23:11 4 Jun '02  
GeneralThis always works... PinsussRoger C13:58 25 Sep '00  
Generalsimple solution! PinsussJarek15:22 31 Jul '00  
GeneralChange it by load a Icon-file PinsussWolfram Steinke19:07 25 Apr '00  
GeneralRe: Change it by load a Icon-file PinsussShahzad Alam Khan4:24 26 Apr '00  
GeneralRe: Change it by load a Icon-file PinsussPeter Lim15:04 3 Oct '00  
GeneralRe: Change it by load a Icon-file PinmemberAnonymous22:22 23 Nov '00  
GeneralRe: Change it by load a Icon-file PinmemberAnonymous4:47 28 Aug '01  
GeneralChange it by load a Icon-file PinsussStephan Strittmatter3:34 1 Mar '00  
GeneralRe: Change it by load a Icon-file PinsussShahzad Alam Khan3:24 2 Mar '00  
GeneralRe: Change it by load a Icon-file works! PinsussStephan Strittmatter21:16 2 Mar '00  
GeneralKia baat hai Shahzad ki PinsussAtif Anwar6:05 17 Feb '00  

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.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 17 Feb 2000
Article Copyright 2000 by Shahzad Khan
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid