"Custom Draw" is a feature shared by all of Microsoft‘s common controls, which allows you to interject your own code while the control is drawing itself. In this way, you can customize the appearance of the control, altering it to suit your needs and tastes.
There have been a number of great articles on custom draw, in the context of various different controls. One of the best is Michael Dunn‘s "Neat Stuff to do in List Controls Using Custom Draw", which illustrates how to tame an unruly custom draw interface to customize the appearance of aCListCtrl
(which is a common listview control). Other examples and a good explanation can be found at MSDN, beginning with the article "Customizing a Control‘s Appearance Using Custom Draw".
"Custom Draw" is not the same thing as "Owner Draw". Custom draw notifications are sent out automatically (it‘s up to you to catch the notifications and process them correctly), whereas for "owner draw", you need to set a style flag (such asLVS_OWNERDRAWFIXED
for a list-view control) before the control will send you aWM_DRAWITEM
message. In custom draw, the control pretty much draws itself completely, and your code customizes its appearance only here-and-there, whereas for owner draw, you must draweverything, usually in an OnDrawItem
handler, even if you want to make the most trivial change. Custom draw is available only for the common controls (like Header controls, List-view controls, Rebar controls, Toolbar controls, ToolTip controls, Trackbar controls, and Tree-view controls) but is not available for the standard (and older) Windows controls (like button controls, combo box controls, list box controls, progress bar controls, static controls, and tab controls); owner draw, on the other hand, is available for all controls.
You can think of custom draw as a kind of "light-weight" owner draw (Michael Dunn‘s words), where the control does most of the work, and you modify just a bit of it. In the hierarchy of things, if you like the way a control looks and how it functions, then use the control "as is"; if you like most of the way the control looks and how it functions, then use custom draw; if you don‘t like the way a control looks but you like how it functions, then use Owner draw; and if you don‘t like the way it looks or the way it functions, then write your own custom control.
Here is a diagram showing the general flow of NM_CUSTOMDRAW notification messages for a list control with two items, each with two sub-items (columns):
OK. That’s a lot of notification messages. But what’s in it for me? Well, lets compare the advatnages of custom draw over owner draw for ListView controls:
Owner Draw | Custom Draw |
Only works with report-view style | Works for any style |
Must do all the drawing yourself | Can choose you own drawing, default drawing of combinations of both. You can also change colours and fonts for default drawing. |
Must draw the entire line (including subitems) in one go | Can handle sub items individually |
http://www.codeproject.com/Articles/8985/Customizing-the-Appearance-of-CSliderCtrl-Using-Cu
http://blog.csdn.net/xiexievv/article/details/6279219