Click here to Skip to main content
15,126,221 members
Articles / Multimedia / GDI
Article
Posted 16 Feb 2000

Stats

157.8K views
24 bookmarked

Replacing the Default MFC Icon

Rate me:
Please Sign up or sign in to vote.
3.32/5 (9 votes)
16 Feb 2000
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.

Share

About the Author

Shahzad Khan
United States United States
No Biography provided

Comments and Discussions

 
Questionvs2010 always Pin
steveh21125-Jul-11 18:53
Membersteveh21125-Jul-11 18:53 
AnswerRe: vs2010 always [modified] Pin
steveh21125-Jul-11 19:09
Membersteveh21125-Jul-11 19:09 
Question#if way? Pin
Super Garrison6-Aug-08 8:13
MemberSuper Garrison6-Aug-08 8:13 
QuestionWhy the second icon not be changed? Pin
Anonymous26-Nov-04 0:21
MemberAnonymous26-Nov-04 0:21 
GeneralLoad Icon from a file Pin
BRWX20-Feb-03 0:12
MemberBRWX20-Feb-03 0:12 
QuestionWhat when i have a multi document template and need different icons Pin
13-Oct-01 0:01
suss13-Oct-01 0:01 
AnswerRe: What when i have a multi document template and need different icons Pin
5-Jun-02 0:11
suss5-Jun-02 0:11 
GeneralThis always works... Pin
Roger Scudder25-Sep-00 14:58
MemberRoger Scudder25-Sep-00 14:58 
Generalsimple solution! Pin
jarek31-Jul-00 16:22
Memberjarek31-Jul-00 16:22 
GeneralChange it by load a Icon-file Pin
Wolfram Steinke25-Apr-00 20:07
MemberWolfram Steinke25-Apr-00 20:07 
GeneralRe: Change it by load a Icon-file Pin
Shahzad Alam Khan26-Apr-00 5:24
sussShahzad Alam Khan26-Apr-00 5:24 
GeneralRe: Change it by load a Icon-file Pin
Peter Lim3-Oct-00 16:04
MemberPeter Lim3-Oct-00 16:04 
GeneralRe: Change it by load a Icon-file Pin
23-Nov-00 23:22
suss23-Nov-00 23:22 
GeneralRe: Change it by load a Icon-file Pin
28-Aug-01 5:47
suss28-Aug-01 5:47 
GeneralChange it by load a Icon-file Pin
Stephan Strittmatter1-Mar-00 4:34
MemberStephan Strittmatter1-Mar-00 4:34 
GeneralRe: Change it by load a Icon-file Pin
Shahzad Alam Khan2-Mar-00 4:24
sussShahzad Alam Khan2-Mar-00 4:24 
GeneralRe: Change it by load a Icon-file works! Pin
Stephan Strittmatter2-Mar-00 22:16
MemberStephan Strittmatter2-Mar-00 22:16 
GeneralKia baat hai Shahzad ki Pin
Atif Anwar17-Feb-00 7:05
sussAtif Anwar17-Feb-00 7: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.