The fifth chapter introduces
In the previous article we introduced some of the WTL features associated with dialog boxes and controls, which are the same as MFC's corresponding classes. This article introduces new classes that implement advanced interface features: control self-painting and custom skin controls, new WTL controls, UI updating, and dialog data validation (DDV).
Special custom drawing and Appearance custom class
Since painting and customizing the appearance controls are a common tool in the graphical user interface, WTL provides several embedded classes to do the tedious work. I will then introduce them, in fact we have done so at the end of the previous example project CONTROLMANIA2. If you're following my lead. Using the Application Generation Wizard to create a new project, don't forget to use the modeless dialog box, and I'll explain in detail why this is done in the UI updating section of the Control in the dialog box, so that you have to use the modeless dialog box for normal work.
Cownerdraw
The control's own painting needs to respond to four messages: Wm_measureitem, Wm_drawitem, Wm_compareitem, and Wm_deleteitem, The Cownerdraw class defined in the Atlframe.h header simplifies these tasks, and you don't need to deal with the four messages using this class, you just link the message to the Cownerdraw and it calls the overloaded functions in your class.
How to link messages to Cownerdraw depends on whether or not you reflect the message to the control, the two methods are somewhat different. The following is a chain of message mappings for the Cownerdraw class, which makes the differences between the two methods more pronounced:
template <class T> class COwnerDraw
{
public:
BEGIN_MSG_MAP(COwnerDraw<T>)
MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem)
MESSAGE_HANDLER(WM_COMPAREITEM, OnCompareItem)
MESSAGE_HANDLER(WM_DELETEITEM, OnDeleteItem)
ALT_MSG_MAP(1)
MESSAGE_HANDLER(OCM_DRAWITEM, OnDrawItem)
MESSAGE_HANDLER(OCM_MEASUREITEM, OnMeasureItem)
MESSAGE_HANDLER(OCM_COMPAREITEM, OnCompareItem)
MESSAGE_HANDLER(OCM_DELETEITEM, OnDeleteItem)
END_MSG_MAP()
};