Discussion:
Custom Control vs. Owner Draw Control?
(too old to reply)
sawer
2008-06-10 09:04:01 UTC
Permalink
Hi

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?

Thanks..
David Lowndes
2008-06-10 11:38:08 UTC
Permalink
Post by sawer
1-) In Terminology, are "custom control" and "owner draw control" same
things?
No

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.
Post by sawer
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?
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
already.

Dave
Tom Serface
2008-06-10 14:09:46 UTC
Permalink
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:

http://www.codeproject.com/KB/buttons/cbuttonst.aspx
http://www.codeproject.com/KB/buttons/cxshadebutton.aspx
http://www.codeproject.com/KB/buttons/cshadebuttonst.aspx
http://www.codeproject.com/KB/buttons/WowButtons.aspx

Tom
Post by sawer
Hi
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?
Thanks..
Ajay Kalra
2008-06-10 14:46:27 UTC
Permalink
Post by sawer
Hi
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?
Thanks..
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.

--
Ajay
sawer
2008-06-10 15:24:00 UTC
Permalink
Thanks for answers.
And with MFC, it is not possible to add control to toolbox as discussed
here:http://forums.msdn.microsoft.com/en-US/vcgeneral/thread/af885aaf-8939-4974-9129-75e182f40e0f/
sawer
2008-06-10 17:15:00 UTC
Permalink
In MSDN:

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?
Ajay Kalra
2008-06-10 17:22:39 UTC
Permalink
Post by sawer
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?
Yes. Not all controls support these. Some support WM_DRAWITEM and some
support NM_CUSTOMDRAW. Some dont support either.

--
Ajay
sawer
2008-06-10 17:39:01 UTC
Permalink
Thank you.
Is there a logic to understand which control supports drawitem or customdraw?
Ajay Kalra
2008-06-10 17:58:31 UTC
Permalink
Post by sawer
Thank you.
Is there a logic to understand which control supports drawitem or customdraw?
Its based on the control. You need to read the docs of each.
Codeproject and Codeguru has tons of relevant sample where you dont
need to worry about the internals(unless you want to).

I picked up about CustomDraw from these articles long time ago:

http://www.microsoft.com/msj/archive/S5D3.aspx
http://www.microsoft.com/msj/archive/S2061.aspx

--
Ajay
Joseph M. Newcomer
2008-06-12 21:58:53 UTC
Permalink
Post by sawer
Hi
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?
****
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.
****
Post by sawer
If not, i understand that custom control means that writing "custom
control dll"
****
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.
****
Post by sawer
and overriding OnPaint() method and this control will be
reusable in other projects.
****
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.
*****
Post by sawer
But owner draw control means changing controls
color for that solution and we only override DrawItem() method. Am i right?
*****
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.
****
Post by sawer
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?
****
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.
joe
****
Post by sawer
Thanks..
Joseph M. Newcomer [MVP]
email: ***@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

Loading...