Replacing the Default MFC Application Icon | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Feb 29, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.