MFC - Replacing default application icon

2019-08-07 17:53发布

问题:

I have a MFC Dialog Application. I would like to replace the application exe icon.

  1. I open the default MFC icon eg. app.ico in the res folder using Axialis IconWorkshop.
  2. Replace all images in the icon.
  3. Save it to appA.ico.
  4. Then I change Filename property of icon IDR_MAINFRAME to res\appA.ico.
  5. Visual Studio icon editor shows the correct image.

But when I build the application, the icon associated to the app.exe still show MFC default icon.

What went wrong?

回答1:

In these cases the Visual Studio designer is a little buggy (or, otherwise, by design but incomprehensible). It's best to edit the .rc code file and change the icon filename there.



回答2:

I think I recall that it is the first icon in the .RC file that is used, no matter what you do, so you might have to edit the .RC file directly, like djeidot says.



回答3:

Sometimes, Windows caches icons. It may not be a problem with your application. Try downloading something like Resource Hacker

and look at your exe file. If the icon looks right, there is an IconCache.db or similar in your appdata\Local folder (depending on Windows version). Delete that and reload Explorer.



回答4:

One of the Visual Studio files caches some resources; unfortunately I can't remember which one at the moment. Rename those files with odd extensions to something else and try a rebuild.



回答5:

I have same problem and solve it by this solution:

  1. Build\Clean Solution
  2. Copy appA.ico again into res folder
  3. Rebuild project


回答6:

I have same problem and solve it by : 1.clear solution 2.open task manager and goto details tab. 3.search for explorer.exe and right click on it and end task. 4.goto File->run new task, type explorer.exe 5.now build the solution and check application icon.



标签: mfc