Add horizontal scrollbar to a combo box

CComboBox has a function called SetHorizontalExtent which doesn’t work. SDK equivalent is CB_SETHORIZONTALEXTENT which also doesn’t work. The reason for this bug is pretty lame, because WS_HSCROLL style for combo box is not set, which in turn the VS dialog editor does not provide :(. So a workaround is to open .rc file in a […]
Continue reading…

 

Check directory or folder empty status

Use function PathIsDirectoryEmpty. Some working facts about this API… Returns false if directory does not exist Returns true is directory is empty Return false if directory contains nested directories but no files Returns false if there are files in directory Returns false if given path points to a directory C: is considered a directory Does […]
Continue reading…

 

Capturing mouse input

There are two functions which helps in capturing mouse input, it’s called SetCapture and ReleaseCapture and a helper function called GetCapture which returns a handle to the capture window associated with the current thread. If no window in the thread has captured the mouse, the return value is NULL. Why do we need to capture […]
Continue reading…

 

Changing scheduling priority of a process at runtime

I had a requirement sometime back to make my process have a higher priority at runtime, so went hunting around for an API which does this and found one with an intuitive name, “SetPriorityClass”. So what is process priority? Process priority is the value which determines priority of a process when it’s being scheduled. If […]
Continue reading…

 

How to handle child window messages in a parent window?

Is there any way to handle child window messages in a parent window? Yes you can use WM_PARENTNOTFIY message or OnParentNotify MFC handler. Note that this message is sent or this function is only called when WS_EX_NOPARENTNOTIFY style is not set. A child controls notifies it’s parent window on… Creation Destruction Mouse button clicks Please […]
Continue reading…

 

Starting command prompt in a particular directory

What I mean is, if we type ‘Start->Run->Cmd.exe’ then command prompt directory is our user directory, for e.g. ‘c:Documents and settingsNibu’. So how can we do this through code is the question? Directory that we see when command prompt starts up is called working directory. Every executable in windows has a working directory which is […]
Continue reading…

 

How to retrieve special folder paths, for e.g. my documents?

SHGetFolderPath is the API that we use to retrieve special folder paths.  Some examples of special folders are as follows… My Documents My Pictures Windows directory System directory Program files Internet history directory Cookies directory etc… So here is a small useful function which retrieves path of any special directory documented for SHGetFolderPath API in […]
Continue reading…

 

How to create protected/readonly pages?

Ever wondered if at all it’s possible to allocate read only chunk of memory. Now you may ask why we would  need to do something like this, well may be just for security reasons. So ideally what happens when we try write to read only memory? We typically get a message box which says… ————————— […]
Continue reading…

 

How to change console application text color?

Easy! call SetConsoleTextAttribute function with appropriate color codes as follows… [sourcecode language=’cpp’]// A generic function call to set color for text being output void SetColor( const int Color ) { SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), Color ); } int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { // Only change foreground color SetColor( FOREGROUND_BLUE ); cout
Continue reading…

 

How to check for keyhit in a windows console application?

For this purpose we use _kbhit function included in conio.h file. Please note that conio.h is a non-standard header file so can’t say if _kbhit will be available in other libraries. The purpose of  _kbhit is to check whether a key has been hit and so then we can use this function to wait till […]
Continue reading…