Gold mine of Visual C++ tricks!
How to Change the Icon of MFC application?
![]()
When you create an MFC application, did you notice the icon of executable? Yes! its that same old icon. But I’ve seen other application with different icon. Well, how to set the icon of executable to give a new face for it?
![]()
Image Courtesy – Flickr
![]()
The secret is, windows will choose the first icon present in executable as exe icon. By default for an MFC application, IDR_MAINFRAME will be the icon resource name and it have the lowest resource value – 128. Follow the steps to add an icon and make set it the first one in executable.
1. Import a new icon by using resource editor.
![]()
2. Let the icon be IDR_ICON1.
3. Now open resource.h and you can see, IDR_MAINFRAME which is the mfc icon, have lowest resource id.
![]()
4. Now edit the resource.h to make IDI_ICON1 as lowest resource id.
![]()
5. Now clean and build your application and check the application icon. Wow! its changed!!!
![]()
The point is, the icon should be the first icon in executable. You can set icon value even to zero. It will work!
![]()
Targeted Audiance – Intermediate.
| Print article | This entry was posted by Jijo Raj on April 5, 2009 at 5:53 pm, and is filed under Visual C++. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
No trackbacks yet.
How to check whether the thread is alive or dead?
about 1 week ago - 1 comment
In multi-threaded environments, sometimes we need to check whether a given thread is alive or not. But how can we check it?
Picture courtesy – Erica Marshall
You can use the function – GetExitCodeThread(). If thread is alive, the function returns STILL_ACTIVE. Have a look at the code snippet.
// Checks whether given thread is alive.
bool IsThreadAlive(const HANDLE More >
C++ Union – Is it still Relevant?
about 1 month ago - No comments
Do you remember the old days, where memory was a premium? At that time, unions were used to save memory by merging multiple variables. Gone are the days where we had memory constraints. Now we have GB’s of RAM itself. So are unions just overhead to language now? Or is it still useful?
The merging property More >
How to set Focus to Different Control on Dialog Startup?
about 1 month ago - 1 comment
Do you want to set the focus to another control on displaying Dialog? Or tried SetFocus() to another control in OnInitDialog() and want to know why its not working? The answer for your ‘Focus’ question is here.
If you are setting the default focus to another control in dialog, then OnInitDialog() should return FALSE. Have a More >
How to Get Project Build Time?
about 1 month ago - No comments
Many times i lost my temper by waiting for the re-build to be finished. So i just attempted to tune and reduce the build time by removing unnecessary includes. At that time I just wondered how to get the build time?
Just follow the steps to enable the ‘Build Time’.
1) Take – Tools > Options.
2) Now More >
Search for Symbols in Visual Studio more Easily
about 3 months ago - 2 comments
Ever tried VisualAssist? Yes man, Its a killer product. The feature that I like most is its Symbol Search. You can specify words and it will list symbols that contain those words. Its very useful if you have a vague idea about the function name that you’re searching for. Have a look at the following More >
C++ Function Pointers Simplified!
about 4 months ago - 2 comments
Background information
Pointer is a variable which holds the address of another variable. Where, function pointer is again a variable which holds the address of a function.
If you think pointers are evil, then function pointers must be Satan for you. Well, is there any easy way to create function pointers from function prototype? More >
How to Set Dialog as TopMost Window?
about 5 months ago - No comments
I always wondered about popularity of Winamp. It has rich custom drawn UI, which made it stand out of the crowd. Did you noticed its “Always on top” feature and wondered about how its implemented? Its time to reveal the secret – How winamp implemented that feature – Staying at the top?
You can use – More >
How to Watch this Pointer – The Wizards Way!
about 7 months ago - 6 comments
How to watch the this pointer? Just add ‘this’ to watch window. Everyone does like that. Isn’t it? But how Visual C++ wizards watch ‘this’ pointer?
The secret is, visual C++ compiler passes this pointer via ECX register. So add (ClassName*)(@ECX) to watch window will give you this pointer. Have a look at the More >
How to get the CPU Name String?
about 8 months ago - 3 comments
While taking the System properties, you have noticed the processor name string. For instance, in my laptop it is – “Intel(R) Core(TM)2 Duo CPU T5250 @ 1.50GHz“. Ever though about how to get this processor name string?
Image Courtesy – Wallpaper Mania.
You can use the function – __cpuid(), which generates the More >
How to Change the Display Orientation?
about 10 months ago - 4 comments
Are you using Windows XP? Press Ctrl+Atl+DownArrow, and then Ctrl+Atl+UpArrow. The screen changes its orientation upside down. isn’t it? But how to turn the screen, upside down programmatically?
Image Courtesy – marieforleo.com
Get the current DEVMODE by calling -EnumDisplaySettings(). Then change orientation by setting DEVMODE.dmDisplayOrientation and calling ChangeDisplaySettings(). Have a look at the code snippet. Code taken More >
about 11 months ago
There’s an easier way.
Just replace your app.ico file with what ever icon file you want.
It even takes care of the multiple-size, 32-bit vista/xp icon as well.
about 11 months ago
Thats Cool! Well, i just want to stress the point – System will select the first icon embudded in executable – which make more sense to non-mfc windows programmers.
Thanks for sharing it.
Regards,
Jijo.
about 8 months ago
Thanks for this!
Worked it for a while before I found the answer on google. Brought me right here.
Great info!
R
about 5 months ago
Thanks for sharing the useful information
about 5 months ago
Always Welcome, Mohit!
Best Regards,
Jijo.