Custom Draw vs. Owner Draw Controls

While most of Windows developers heard about and eventually used owner-draw controls, fewer know about custom-draw controls. Both types of controls allow customization but they are pretty different. So let’s have a quick look at each one.

Owner Draw Controls

An owner-draw control is a common Windows control that have a special owner-draw style set.

  • BS_OWNERDRAW for button controls;
  • LBS_OWNERDRAWFIXED or LBS_OWNERDRAWVARIABLE for listbox controls;
  • LVS_OWNERDRAWFIXED for listview controls;
  • and so on…

Once the owner-draw style is set, the “owner” has the whole drawing responsibility. For that purpose, have to handle WM_DRAWITEM notification (sent to parent window) and perform drawing. In MFC, can also handle WM_DRAWITEM reflected message in the control’s MFC class or override DrawItem virtual function, if available.
Additionally, in some cases can handle WM_MEASUREITEM, to modify the size of control items. See also WM_COMPAREITEM and WM_DELETEITEM which also can be useful when developing  owner-draw controls.
You can see how owner-draw controls are made by having a look, for example, in the implementation of CBitmapButton and CCheckListBox MFC classes.

Custom Draw Controls

Custom-draw controls have no special style. We say that a control is custom-draw if handles the NM_CUSTOMDRAW notification (sent via WM_NOTIFY message). This case, there is no necessary for the “owner” to perform the whole drawing, but can change some defaults. For example, can tell the system to fill an item with some custom color or perform some additional drawing after the default drawing has been done.
Here is an example of custom-draw listvew control, having alternate item colors and a selection rectangle around a particular subitem.

Custom-Draw Listview Control

Custom-Draw Listview Control



Resources

See also

Leave a Reply