Custom draw 和 Owner draw 的区别

"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

时间: 2024-11-10 14:07:33

Custom draw 和 Owner draw 的区别的相关文章

MFC自绘控件学习总结第二贴

首先感谢大家对第一帖的支持,应一些网友烈要求下面我在关于上一贴的一些补充和说明(老鸟可以无视)这一贴是实战+理论不知道第一帖的先看第一帖:http://topic.csdn.net/u/20110710/19/5209f358-31c8-4057-b108-02155a417fd0.html 1).补充个高级可重载函数PreSubclassWindow(),我的理解是允许用户在子类化之前再做一额外些处理 ,这个重载函数也是非常重要的,要引起相当的注意.可以在这里改变控件的大小,位置,窗口样式,字

Android应用层View绘制流程之measure,layout,draw三步曲

概述 上一篇博文对DecorView和ViewRootImpl的关系进行了剖析,这篇文章主要是来剖析View绘制的三个基本流程:measure,layout,draw,只有把这三个基本流程搞清楚了,平时在自定义View的时候才会有清晰的思路!开始进入正题. View的measure过程 三个流程均是从ViewRootImpl的performTraversals方法开始的,如下所示: private void performTraversals() { ...... int childWidthM

Android UI 绘制过程浅析(四)draw过程

前言 draw是绘制View三个步骤中的最后一步.同measure.layout一样,通常不对draw本身进行重写,draw内部会调用onDraw方法,子类View需要重写onDraw(Canvas),以完成最终的绘制. 如果一定要重写draw(Canvas)的话,需要在方法的开始处调用super.draw(canvas). draw过程 draw内部具体做了什么事情,在View.java的源码注释中已经做了非常详细的介绍 /* * Draw traversal performs several

android6.0 Activity(五) Activity的测量(Measure)、布局(Layout)和绘制(Draw)

 原文:http://blog.csdn.net/luoshengyang/article/details/8372924   http://blog.csdn.net/feiduclear_up/article/details/46772477.在这两者基础上改动了一下. Android应用程序窗口的绘图表面在创建完成之后,我们就可以从上到下地绘制它里面的各个视图了,即各个UI元素了.不过在绘制这些UI元素之前,我们还需要从上到下地测量它们实际所需要的大小,以及对它们的位置进行合适的安排,

Unity性能优化之 Draw Call原理<转>

Unity(或者说基本所有图形引擎)生成一帧画面的处理过程大致可以这样简化描述:引擎首先经过简单的可见性测试,确定摄像机可以看到的物体,然后把这些物体的顶点(包括本地位置.法线.UV等),索引(顶点如何组成三角形),变换(就是物体的位置.旋转.缩放.以及摄像机位置等),相关光源,纹理,渲染方式(由材质/Shader决定)等数据准备好,然后通知图形API——或者就简单地看作是通知GPU——开始绘制,GPU基于这些数据,经过一系列运算,在屏幕上画出成千上万的三角形,最终构成一幅图像. 在Unity中

(转)Unity3D - 性能优化之Draw Call

Unity(或者说基本所有图形引擎)生成一帧画面的处理过程大致可以这样简化描述:引擎首先经过简单的可见性测试,确定摄像机可以看到的物体,然后把这些物体的顶点(包括本地位置.法线.UV等),索引(顶点如何组成三角形),变换(就是物体的位置.旋转.缩放.以及摄像机位置等),相关光源,纹理,渲染方式(由材质/Shader决定)等数据准备好,然后通知图形API——或者就简单地看作是通知GPU——开始绘制,GPU基于这些数据,经过一系列运算,在屏幕上画出成千上万的三角形,最终构成一幅图像. 在Unity中

C#Draw

命名空间 using System.Draw; using System.Draw.Drawing2D; 在form等控件的 事件中 添加 paint事件 ///////画各种形状(空心)/////// e.Graphics.Clear(Color.AliceBlue);//清楚整个绘画面并以制定的颜色(这里是爱丽丝蓝--Color.AliceBlue)填充 e.Graphics.DrawArc();//画弧线 e.Graphics.DrawCurve();//不闭合曲线 e.Graphics.

Android View 绘制流程(Draw) 完全解析

前言 前几篇文章,笔者分别讲述了DecorView,measure,layout流程等,接下来将详细分析三大工作流程的最后一个流程--绘制流程.测量流程决定了View的大小,布局流程决定了View的位置,那么绘制流程将决定View的样子,一个View该显示什么由绘制流程完成.以下源码均取自Android API 21. 从performDraw说起 前面几篇文章提到,三大工作流程始于ViewRootImpl#performTraversals,在这个方法内部会分别调用performMeasure

3.NGUI Draw Call(渲染调用)

在Unity中,每次引擎准备数据并通知GPU的过程称为一次Draw Call.Draw Call值越低,会得到更好的渲染性能. NGUI 查看Draw工具(NGUI-OPEN-Draw Call Tool) NGUI 方面的Draw Call 优化: (1)     打包图集 一.每个材质/纹理的渲染一定是会产生DrawCall的,这个DrawCall只能通过打包图集来进行优化. 二.从功能角度进行划分,例如UI可以划分为公共部分,以及每个具体的界面,功能上,显示上密切相关的图片打包到一起