Replacing the Default MFC Application Icon

Many new 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:

(i). copy the new icon file in .../res folder. This step is not essential but its better to put all the resources in one folder.
(ii). 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 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.



Comments

  • MFC-Icons-ID

    Posted by Legacy on 12/29/2002 12:00am

    Originally posted by: McBen

    Simply take the Icon Resources IDs:
    AFX_IDI_STD_FRAME
    and
    AFX_IDI_STD_MDIFRAME

    Reply
  • How to assign different icons for different versions of a program

    Posted by Legacy on 02/22/2002 12:00am

    Originally posted by: Keivan

    Hi ,
    I have written a program and used preprocessor definition to build two different versions of it. The thing that I want to have is: each of those version has its own icon. How can I do this? Actually I should mention that I edited resource file manually and added #ifdef directive for it in ICON section and it worked. But the problem is after I make any change in resource file and compile it, resource compiler removes #ifdef directives from resource file and I have to add them again.
    Any idea?

    Thanks

    Keivan

    Reply
  • Thanks.

    Posted by Legacy on 08/09/2001 12:00am

    Originally posted by: Li Baoping

    A very good reminder for me.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds