Click here to Skip to main content
15,794,240 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Does anyone know how to set the program icon dynamically in a VC6 doc-view application? The icon in the upper left of the title bar is the 16x16 IDR_MAINFRAME icon, and the icon shown for the executable on the desktop is the 32x32 IDR_MAINFRAME icon. Also any file shown on the desktop opened with that program will have the icon displayed with that file. I have an application where I want to let the user select an icon, then I want to show that icon in the upper left of the title bar, and also set the icon associated with any generated files on the desktop to the selected icon. So it sounds like dynamically changing the IDR_MAINFRAME icon to another icon would have the behavior I'm trying to implement. I have all the icons the user can select in my resource (IDI_ICON1, IDI_ICON2, etc). Thanks.
Updated 10-Jun-11 7:51am

1 solution

You're asking 3 different things

I'll explain how to change the application window's icon.
(I'm not used to working with MFC, so i'll use some API)

Load the icon from your resource using
HICON icn = ::LoadIcon(::GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICONx))

You may set the icon using SetClassLong

You must use the Shell Links api to set your desktop shortcut's icon. Check msdn for some examples

To set your application's documents' icons, modify the registry
(assuming your document's extension is .abc)
Set icons in this path
The value will be the path to your executable file, followed by a number
Eg: C:\YourApp.exe,0
where the number 0 (or 1,2) is the order number of the icon resources in your executable.
Just check out some registry keys to understand
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900