How to trim white space before and after a string?

I will describe in this post three ways to trim a string of given characters… Using custom function for std::string Using CString Using StrTrim shell API function. Using custom function for std::string Its bit strange that std::string doesn’t provide a Trim function ๐Ÿ˜• , but hey since we’ve got head upon our shoulders we’re gonna […]
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…

 

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…

 

How to register a Hotkey for your application?

Now what’s a hotkey? An easy definition would be a key that remains hot throughout the lifetime of an application. Whenever you press a hotkey it does it’s work no matter where the focus is or where the input is directed to, etc. Here is a screenshot and a sample application(Right click and save as […]
Continue reading…

 

To move a captionless dialog.

Have you ever wondered how do people move dialogs by simply clicking anywhere inside the dialog and dragging them. Have you ever wondered how caption-less dialogs can be dragged around. If it is so then let me tell you that you can do the same with just few lines of code… Here goes the code: […]
Continue reading…

 

A round dialog box!

Ever wondered how those cute little round dialog boxes are created. I too wondered for some time. But let me tell you it is easy, take a look: Do this from OnInitDialog! [sourcecode language=’cpp’]//Create a region object globally. CRgn m_EllipticRegion; //a rect object CRect crDialogRect; //get your dialog size this->GetClientRect(crDialogRect); //Now create the elliptic region […]
Continue reading…

 

How to convert ANSI string to UNICODE string and vice versa?

Well quite simple,ย  but still quite frequently asked in forums… ๐Ÿ™‚ There are two macros that does this for us. They are as follows. Note: You must include atlconv.h A2W – ANSI to UNICODE W2A – UNICODE to ANSI Before using these two macros you have to use this macro too… USES_CONVERSION Here is a […]
Continue reading…

 

When to use OnDrawItem, DrawItem and OnPaint?

Note: This post assumes that owner draw flag for controls is set. OnDrawItem is mainly provided to facilitate owner drawing child controls in a parent window class without sub classing them. An e.g. can be a tab/button/listbox/combobox/menu control, we can ownerdraw these without sub classing using this function. Note that OnDrawItem is called as result […]
Continue reading…

 

Restricting window size

Easy! Handle WM_GETMINMAXINFO, LPARAM of this message points to a MINMAXINFO structure. Fill out necessary information into this structure like minimum and maximum tracking size, maximum position, maximum size. If you’ve handled and filled out necessary information then return FALSE to so that the changes get’s applied. If you are using MFC then add a […]
Continue reading…