How to identify a stale handle?

Lets suppose you are keeping handles of all processes running in a system using OpenProcess, now it’s just normal that some processes may exit, but since you have a valid handle there is no way to tell whether the process is still running or whether it has exited. You cannot check for NULL since the […]
Continue reading…

 

Redistributables for different VC versions starting from VC 2005

If you want to re-distribute the applications that you developed in different versions of VC then you need to install their redist packages on such target machines, following are the redists that I use… Redistributable for VC 2005 applications is here Redistributable for VC 2008 applications is here Redistributable for VC 2008 feature pack applications […]
Continue reading…

 

How to limit the text entered into an edit/richedit control?

Call CEdit::SetLimitText or send EM_LIMITTEXT windows message to an edit control. There are some caveats associated with this functionality… This limitation does not affect the amount of text entered via a call to SetWindowText, or WM_SETTEXT. This limitation does not hold true for paste operation. This limitation does not affect text already entered into an […]
Continue reading…

 

What’s the size limit of a vector?

Use std::vector::max_size() function. Don’t confuse this function with std::vector::capacity() and std::vector::size() functions. vector::capacity() tells us when a vector will be reallocated and vector::size() tells us the count of elements inserted into a vector. Source code of vector::max_size looks like this… [sourcecode language=’cpp’]_SIZT max_size() const _THROW0() {    // estimate maximum array size    _SIZT _Count […]
Continue reading…

 

How to create a topmost window using SetWindowPos?

A topmost window is one which stays on top of other windows even while it’s not in focus. Normally all application popup windows will go to background once they lose focus but a topmost window doesn’t. Let me explain or show you the code which does this. Everybody knows how to achieve this but still […]
Continue reading…

 

Changing background color of a console application?

Changing background color of a console application can be accomplished in two ways… Through console application API’s provided by Microsoft. Through color command in windows. The second one is the easiest, let me show you how to do so… [sourcecode language=”cpp”]// This will change the background to crimson and foreground color to white const int […]
Continue reading…

 

Capturing text from under your mouse cursor!

Ever felt the need to capture text from under your mouse cursor. I’ve made a small sample application which does this. Check out!Download (Rename to exe or save as exe) Take a look at this screenshot, notepad contents has been captured into my application’s value field. Name and value are two different things. For e.g. […]
Continue reading…

 

Using DlgDirList, DlgDirListComboBox, CB_DIR, LB_DIR, DlgDirSelect, DlgDirSelectEx, DlgDirSelectComboBox, DlgDirSelectComboBoxEx set of functions

DlgDirList, DlgDirSelect, DlgDirListComboBox, CB_DIR and LB_DIR are some functions and event ids that helps us in making our normal list and combo boxes more powerful by enabling directory and file listing capabilities with just one function call or one event. Take a look at this screenshot before proceeding, the exe is here(save as exe), easy to […]
Continue reading…

 

Progress messages or progress bars in a console application, Win2000 and Linux style

Ever seen that white progress bar in Windows 2000 while it loads and that spinning stick while Linux is being installed. Out of my curiosity I wrote some functions which emulates these progress bars. You can optimize/customize these functions for your needs, a thank you message will do the trick with me! Take a look […]
Continue reading…