Gold mine of Visual C++ tricks!
| Print article | This entry was posted by Jijo Raj on April 11, 2008 at 6:14 pm, and is filed under Compiler Extension. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
No comments yet.
No trackbacks yet.
How to check whether the thread is alive or dead?
about 6 months ago - 3 comments
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
How to set Focus to Different Control on Dialog Startup?
about 6 months 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
How to Get Project Build Time?
about 6 months 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
Search for Symbols in Visual Studio more Easily
about 9 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
C++ Function Pointers Simplified!
about 10 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?
How to Set Dialog as TopMost Window?
about 10 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 –
How to Watch this Pointer – The Wizards Way!
about 1 year 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
How to get the CPU Name String?
about 1 year 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
How to Change the Display Orientation?
about 1 year 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
How to Delete Duplicate entries from STL containers?
about 1 year ago - 4 comments
If you want to remove duplicate items, you can go for stl::set. But what to do if you want to delete duplicate data from other containers?
Picture Courtesy – Squidoo
You can use std::unique() algorithm to remove adjacent duplicate items. So at first, sort your data, then call std::unique(). Now all the duplicate data will be rearranged
Automatically link required libraries.
In our projects we use number of 3ed party API’s especially from platform SDK and other components and one burden is finding the libraries for those API’s. For Microsoft provided API’s since they have strong documentation, finding the library for particular API is not so tedious. But for other vendors, It may be. We need to dig a lot for finding the lib of that particular API. How can we get rid from this?
You can you #pragma comment( lib, “LibraryName” ) to specify the necessary library file in the header file itself. For e.g. See the following header file.
// EventLog.h class EventLog { … }; #ifdef _DEBUG // If it’s a debug version… #pragma comment( lib, "MyEventLogLibd.lib" ) #else // Ooooh!!! Its release version. #pragma comment( lib, "MyEventLogLib.lib" ) #endifIf we include the EventLog.h header file, the library required will be automatically included. I dream for the day on which all SDK headers auto includes their libraries…
Target audiance – Intermediate.