MFC Custom Controls - Subclassing

MFC allows you to create a C++ class, which is derived from a base class - subclassing in the C++ definition of the word - to change the behavior and the visual appearance of the control described by the base class. This is very different from the SDK meaning of "subclassing," which is used only to change the behavior, but not the appearance.

As an example: If you look at Chris Maunder's subclassing article, you will notice that he changes one of the style bits in his subclassed button to make it owner-drawn, and then overrides the OnDrawItem virtual function in his derived class. In SDK programming, this is simply implementing an owner drawn control. Hidden by MFC is the fact that the WM_DRAWITEM message is sent to the parent of the control, and the parent is responsible for determining which control is to be drawn, its state, and then drawing it. This is not subclassing; Rather, this is owner-drawing.

On the other hand, if you look at Daniel Kopitchinski's message handling article, the behavior of an edit control is modified by preventing certain keys from getting to the control. Considering that the control does not send every keystroke to its parent in a WM_CHAR message, how can the author be overriding this message handler? This is subclassing in the SDK sense: By changing the function that handles messages for the edit control, the author was able to filter what the control actually received

Windows provides support for "owner draw" controls and menus. These are Windows messages sent to a parent window of a control or menu that allow you to customize the visual appearance and behavior of the control or menu.

MFC directly supports owner draw with the message map entries:
CWnd::OnDrawItem
CWnd::OnMeasureItem
CWnd::OnCompareItem
CWnd::OnDeleteItem

You can override these in your CWnd-derived class (usually a dialog or main frame window) to implement the owner-draw behavior.

DrawItem messages makes things easier for developers, we get OD flags that tells which action requires painting.
ODS_CHECKED
ODS_FOCUS
ODS_DISABLED.
etc

References:

MFC Custom Controls - http://msdn.microsoft.com/en-us/library/bk2h3c6w(VS.71).aspx

Customizing Common Controls - http://www.ddj.com/184410273

MFC Quick Reference -
http://www.digilife.be/quickreferences/QRC/Microsoft%20Foundation%20Classes%20(MFC)%20Quick%20Reference.pdf

http://www.codeproject.com/KB/dialog/ownrdrwsubcls.aspx?display=Print http://nibuthomas.com/2008/06/28/when-to-use-ondrawitem-drawitem-and-onpaint/

Creating a Custom Tree Control Using the SDK –
http://www.ddj.com/showArticle.jhtml?documentID=ddj9709c&pgno=4

CheckComboBox - http://uttermatter.com/stdd/Implementation/CD/source%20code/CheckComboBox.cpp

CCheckListBox – http://msdn.microsoft.com/en-us/library/84cw5ysf(VS.80).aspx