Custom Control vs. Owner Draw Control?

Custom Control vs. Owner Draw Control?

Post by c2F3ZX » Wed, 11 Jun 2008 18:04:01


Custom Draw, Owner Draw, Custom Control, Owner Draw Control...

Overriding DrawItem() Method, Overriding OnPaint() Method, OnCustomDraw()
Method, WM_CTLCOLOR Handler, adding custom control which is in toolbox and
"Custom Control DLL"...

I started to search control development in MFC to learn how to write
(stylish)controls but it seems that it will be difficult and confused...
I have basic 2 questions, if you help me to find answers i will be very glad.

1-) In Terminology, are "custom control" and "owner draw control" same
things? If not, i understand that custom control means that writing "custom
control dll" and overriding OnPaint() method and this control will be
reusable in other projects. But owner draw control means changing controls
color for that solution and we only override DrawItem() method. Am i right?

2-) As seen and i am correct, there are many ways to draw a control with
different style and colors. If i want to make a button with gradient color
and want to add it in Toolbox to use in different projects and there will be
2 color options that developer will adjust for drawing button in properties
window when add it to form and select it. Which way must i choose? What must
be the roadmap?


Custom Control vs. Owner Draw Control?

Post by David Lown » Wed, 11 Jun 2008 20:38:08

>1-) In Terminology, are "custom control" and "owner draw control" same


A custom control would be an entire control that you write yourself.
An owner drawn control is a facility that you can use with some
existing (standard) controls that lets you do the painting of it.
There's also custom draw which is similar to owner drawn, but often
much simpler.

I think that would need to be a custom control - albeit one that you
could create by deriving from a standard button that you owner draw. I
hope that's not too confusing!
There are probably 3'rd party controls available that do what you want



Custom Control vs. Owner Draw Control?

Post by Tom Serfac » Wed, 11 Jun 2008 23:09:46

To add to David's reply.

I typically would just add a regular button then go back and edit the .h
file to change it to my specialty button before compiling. There is
probably a way to add it to the toolbox, but I've never found it worth the
trouble to figure it out since it's so easy to just change CButton to
CMyButton or something like that.

One of these may already do what you need or, at least, give you some
guidance on how to get started writing your own:


Custom Control vs. Owner Draw Control?

Post by Ajay Kalr » Wed, 11 Jun 2008 23:46:27

In addition to others, a custom control doesnt need to be owner drawn
at all. You can have a custom control which simply uses the default
window procedure for handling all messages.

Custom Control vs. Owner Draw Control?

Post by c2F3ZX » Thu, 12 Jun 2008 00:24:00

Thanks for answers.
And with MFC, it is not possible to add control to toolbox as discussed

Custom Control vs. Owner Draw Control?

Post by c2F3ZX » Thu, 12 Jun 2008 02:15:00


NM_CUSTOMDRAW: This message is sent by some common controls to notify their
parent windows about drawing operations

WM_DRAWITEM: This message is sent to the owner window of an owner-drawn
button or menu when a visual aspect of the button or menu has changed.

Is there a difference between override CustomDraw method and DrawItem method?

Custom Control vs. Owner Draw Control?

Post by c2F3ZX » Thu, 12 Jun 2008 02:39:01

Thank you.
Is there a logic to understand which control supports drawitem or customdraw?

Custom Control vs. Owner Draw Control?

Post by Joseph M. » Sat, 14 Jun 2008 06:58:53

A custom control is a control where you take responsibility for everything. This includes
painting it. Owner-draw refers to a technique by which an existing control lets you
"hook" the drawing logic and do the drawing yourself. For example, an owner-draw CListBox
implements all the standard CListBox bheavior (scrolling, selecting, double-clicking,
etc.) and all you have to do is supply a little routine to draw the image. A custom
control that emulated CListBox would have to deal with ALL the details of making a
CListBox work.
No. A DLL is merely one way to implement it; you do not need to use a DLL at all for a
custom control. ActiveX controls are different, and they require a separate .DLL file
(called a .OCX file) but I have dozens of custom controls that involve no DLLs at all.
It might be easier to reuse in another project if it is in a DLL, but copying the source
from one project to another works well, too.
Owner-draw may or may not involve changing control colors; the standard controls will
allow changing the colors without creating a "custom" control, just subclassing the
control and implementing an OnCtlColor handler.
Buttons are a bit obnoxious because they require owner-draw to draw the background. But
if you want to have the user select teh parameters, you're in the realm of doing an
ActiveX control and creating custom properties for it, and that's more complex.

If I wanted to do this in a simple fashion, I'd subclass CButton (probably, I'd start with
my Better Bitmap Button class, CImageButton) and add methods the programmer called to set
teh parameters. It is a great deal easier than trying to create a whole OCX button.
Joseph M. Newcomer [MVP]
MVP Tips: