I am using MFC 6.0 to program and want to replace the default document file icon ( such as .doc). I tried to replace the default "res\\ProjectDoc.ico" with the new "res\\NewIcon.ico" on the project .rc file , but it does not work . Is there any solution I can try now?
I make a MFC application, and its contents is stored to file , such as filename1.abc. when I look at the filename1.abc in the windows explorer, the .abc file displays with the icon of default mfc icon, such as the "res\\ProjectDoc.ico". I want to change the old icon with the new icon, i.e "res\\NewIcon.ico", makes the file displayed with the icon of "res\\NewIcon.ico" in the windows explorer. so I edits the project .rc file, replaces the old statement
{ IDR_DEVICETYPE ICON DISCARDABLE "res\\ProjectDoc.ico" }
with the new statement
{ IDR_MAINFRAME ICON DISCARDABLE "res\\NewIcon.ico" }
, the program compile , execute, save the contents to filename2.abc.when I looks at filename1.abc, filename2.abc in the windows explorer, these files (.abc file) still displays with the icon of "res\\ProjectDoc.ico", not I wanted icon of "res\\NewIcon.ico". how do I do that ?
Icons have two different device images: standard and small.
Explorer is using small that you probably did not change. In resource editor choose appropriate device image and edit small too.
If you want to use different set of icons from different file make sure both device images are present and after importing icon to resources you would have to assign ID that has the lowest value for this icon in resource header.
Change original icon ID and assign IDR_MAINFRAME to a new icon.
There are only 10 types of people in the world: Those who understand binary and those who do not.
take the above methods, run the application, the window icon has been changed. look at the project\\debug directory , the .exe file icon has been changed .
further more, I also want to change the document file icon displayed in the Explorer. below I attach a simple MFC project (aaa) developed in the standard document/view way , list the programming steps:
first , in the CDocument-Derived class, declare member variable (CString m_displaystr), initialize m_displaystr in the CDocument-Derived class constructor.
secong, in the CView-Derived class OnDraw(CDC* pDC) function , display the CDocument member m_displaystr, and call CDocument::SetModifiedFlag().
third, copy two icon file to the project\\res\\ directory(computer.ico and doc.ico). in the .rc file , replace the old statments
{
IDR_MAINFRAME ICON DISCARDABLE "res\\aaa.ico"
IDR_AAATYPE ICON DISCARDABLE "res\\aaaDoc.ico"
}
withe the following statements
{
IDR_MAINFRAME ICON DISCARDABLE "res\\computer.ico"
IDR_AAATYPE ICON DISCARDABLE "res\\doc.ico"
}.
that's all.
then , compile and execute, the text stored in the CDocument-Derived class member variable m_displaystr shows in the client area, the mainframewnd icon has been changed to the computer.ico, close the application , the Prompting saving dialog be poped up , select Yes, save the results to file (such as test.aaa).
looking at the aaa.exe file in the Explorer, aaa.exe file has the icon of computer.ico. looking at the test.aaa file in the Explorer, test.aaa doesn't has the icon of doc.ico.
what methods can I take to let the file test.aaa has the icon of doc.ico in the Explorer?
I don’t know why are you doing it a hard way. changing icon can be done in resource editor without directly editing rc file. There is no need for following steps you have posted.
Anyway now I see your problem. Windows after document is registered by calling RegisterShellFileTypes caches icon and display it from cache.
Depending on Windows version this is handled differently. Delete cache file or cache for your app and everything will show correctly.
There are only 10 types of people in the world: Those who understand binary and those who do not.
I do not know, I don’t run Windows 2000.
I think any search engine (Google) would find it for you if you specify right keywords. For example: icon cache windows 2000. Try it.
There are only 10 types of people in the world: Those who understand binary and those who do not.
following your advice , I begin search with the google. A lot of articles, especial a VC project to change the icon . below is the core code to delete cache file.
putting the above code under the RegisterShellFileTypes(), executing the program, test.aaa file icon has been changed in the explorer. but it is the icon of "computer.ico", not "doc.ico". looking at the registry, under the key of Aaa.Document , there isn't the DefaultIcon subkey. Which function in MFC set the DefaultIcon subkey in the registry ?
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.