|
A custom control is an enhanced tool which has been tailored to get
additional features over an ordinary control. As an example, an ordinary list
control displays lists of text, but a customized list control can be made to
display rectangles of color for the user to make a color selection. This is also
referred to as an owner-draw control, since we can paint anything we want in a
custom control.
The operating system supports owner-draw controls by sending specific messages
to the parent window of the control that allow us to customize the visual
appearance and behavior of the control. These messages are handled in the MFC’s
message maps (in CWnd-derived classes) with: OnDrawItem(),
OnMeasureItem(), OnCompareItem(), and OnDeleteItem(). These
functions allow us to access the data structures in which we can specify the
drawing action that is required, specify the measurement and dimensions of our
item, specify the position of the item, or specify the deletion of item-specific
data. We could override these functions in our control class to implement the
owner-draw behavior, and the control can do its own drawing without any help
from the parent.
MFC provides default implementation for the standard owner-draw messages. This
default implementation will decode the owner-draw parameters and delegate the
owner-draw messages to the controls. This is called self-draw, since the drawing
code is in the class of the control, not in the owner window.
MFC provides the custom control classes like CBitmapButton derived from CButton,
CCheckListBox and CDragListBox, which are derived from CListBox. MFC has even
introduced the button styles BS_BITMAP and BS_ICON which offer functionality
similar to the CBitmapButton class. CBitmapButton class allows you to easily
create buttons that are labeled with graphics instead of text. The bitmaps are
customized by dynamically subclassing them using the function SubclassDlgItem().
|