The difference between Custom draw and Owner draw

Source: Internet
Author: User

"Custom Draw" is a feature gkfx by all of Microsoft's common controls, which allows you to interject your own code while The control is drawing itself. In this is the customize the appearance of the control, altering it to suit your needs and tastes.

There has been a number of great articles on custom draw, in the context of various different controls. One of the best are Michael Dunn ' s "Neat Stuff to does in List Controls Using Custom Draw", which illustrates how to tame an Unruly custom Draw interface to customize the appearance of a CListCtrl (which is a common ListView control). Other examples and a good explanation can is found at MSDN, beginning with the article "Customizing a Control ' s appearance Using Custom Draw ".

"Custom Draw" is notThe same thing as "Owner Draw". Custom draw Notifications is sent out automatically (it's up to catch the notifications and process them correctly ), whereas for ' owner draw ', need to set a style flag (such asLVS_OWNERDRAWFIXEDFor a List-view control) before the control would send you aWM_DRAWITEMMessage. In custom draw, the control pretty much draws itself completely, and your code customizes it appearance only here-and-the Re, whereas for owner draw, must draweverything, usually in anOnDrawItem handler, even if you want and make the most trivial change. Custom Draw is available-common controls (like Header controls, List-view controls, Rebar controls, Toolbar C Ontrols, ToolTip controls, Trackbar controls, and Tree-view controls) but isn't available for the standard (and older) Wi ndows controls (like button controls, combo box controls, list box controls, progress bar controls, static controls, and T AB controls); Owner draw, on the other hand, was 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 the-the-same control looks and how it functions, then use the control "as is"; If you have the looks and how it functions, then use custom draw; If you don't like the the-the-looks-a-control-you-like-how-it functions, then use Owner draw; And if you don't like the it looks or the the-the-functions, then write your own custom control.

Here are a diagram showing the general flow of NM_CUSTOMDRAW notification messages for a list control with the items, each With sub-items (columns):

Ok. That's a lot of notification messages. But what's the 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-Cuhttp:// blog.csdn.net/xiexievv/article/details/6279219

The difference between Custom draw and Owner draw

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.