Can we override a control's OnPaint ? 
Author Message
 Can we override a control's OnPaint ?

I want to add some drawing to a CButton derived control. I want the button
to look exactly as normal but with a black square around the text. Is it
possible to add an Message Map entry for WM_PAINT and override OnPaint. I
tried it, calling CButton::OnPaint in it and putting my code after, but the
button is drawn as normal and I don't see my drawing.

1- Can you tell me if it's possible this way or if I need use an owner drawn
control and why ?
2- In an owner drawn control, do I have to do all the painting or I can call
CButton::OnPaint and add some drawing after that ?

Thanks

Steve



Wed, 16 Jan 2002 03:00:00 GMT  
 Can we override a control's OnPaint ?

You will need to use an owner drawn button. (Why? Because Bill says so!!)

For your specific example (black square around the text), you will have to
do all the drawing yourself. If you wanted only to change the background or
text color, you could override CWnd::OnCtlColor().

This is not particularly onerous, however, and it gives you complete control
over the font of your button text, shadows, etc., although don't forget that
you do have to draw the up, down, disabled, and focus states for your
button.

When you get to the point that you want to draw that focus rectangle around
the caption, here is how to draw that dotted line properly:

  hPen = ExtCreatePen ( PS_COSMETIC | PS_ALTERNATE,
         1, &logBrush,0, NULL) ;

HTH
Chris Hough



Wed, 16 Jan 2002 03:00:00 GMT  
 Can we override a control's OnPaint ?
There are examples at CodeGuru.com where they override OnPaint. For example,
CSeparator is a class derived from CStatic with OnPaint overriden to do the
custom painting. I wonder why use user drawn controls if we can do that this
way ?

The controls already have code to draw them, isn't it possible to use this
code by calling the base class's OnPaint and then putting the additional
drawing code after the call returns ? Or must we redo ALL of the painting
ourself

Steve


Quote:
> You will need to use an owner drawn button. (Why? Because Bill says so!!)

> For your specific example (black square around the text), you will have to
> do all the drawing yourself. If you wanted only to change the background
or
> text color, you could override CWnd::OnCtlColor().

> This is not particularly onerous, however, and it gives you complete
control
> over the font of your button text, shadows, etc., although don't forget
that
> you do have to draw the up, down, disabled, and focus states for your
> button.

> When you get to the point that you want to draw that focus rectangle
around
> the caption, here is how to draw that dotted line properly:

>   hPen = ExtCreatePen ( PS_COSMETIC | PS_ALTERNATE,
>          1, &logBrush,0, NULL) ;

> HTH
> Chris Hough



Wed, 16 Jan 2002 03:00:00 GMT  
 Can we override a control's OnPaint ?
Only certain controls support owner-draw and the static control is not
one--at least not offically.

CButton, CListBox, CComboBox, CTreeCtrl, CListCtrl and CMenu support owner
draw. SS_OWNERDRAW is defined in winuser.h, but it's use is not documented.

If only need to change:
1.) the background, the text color, or the text background color; then look
into OnCtlColor()
2.)Sure, if there is an OnPaint() example, I'd say use it.

Kurt


Quote:
> There are examples at CodeGuru.com where they override OnPaint. For
example,
> CSeparator is a class derived from CStatic with OnPaint overriden to do
the
> custom painting. I wonder why use user drawn controls if we can do that
this
> way ?

> The controls already have code to draw them, isn't it possible to use this
> code by calling the base class's OnPaint and then putting the additional
> drawing code after the call returns ? Or must we redo ALL of the painting
> ourself

> Steve



> > You will need to use an owner drawn button. (Why? Because Bill says
so!!)

> > For your specific example (black square around the text), you will have
to
> > do all the drawing yourself. If you wanted only to change the background
> or
> > text color, you could override CWnd::OnCtlColor().

> > This is not particularly onerous, however, and it gives you complete
> control
> > over the font of your button text, shadows, etc., although don't forget
> that
> > you do have to draw the up, down, disabled, and focus states for your
> > button.

> > When you get to the point that you want to draw that focus rectangle
> around
> > the caption, here is how to draw that dotted line properly:

> >   hPen = ExtCreatePen ( PS_COSMETIC | PS_ALTERNATE,
> >          1, &logBrush,0, NULL) ;

> > HTH
> > Chris Hough



Thu, 17 Jan 2002 03:00:00 GMT  
 Can we override a control's OnPaint ?
It might be easier if it is owner draw, just cuz you can do a drawtext to
draw the text out and keep the bounding rect and use that to draw the box.
If you override the OnPaint() (if that is possible), you need to somehow get
the text rect which I'm not sure how you would do so.

If you CAN override the OnPaint() and have it draw some stuff, you may want
to set the window text to "" and then draw that text yourself (just so you
can easily have the rect)

Matt


Quote:
> There are examples at CodeGuru.com where they override OnPaint. For
example,
> CSeparator is a class derived from CStatic with OnPaint overriden to do
the
> custom painting. I wonder why use user drawn controls if we can do that
this
> way ?

> The controls already have code to draw them, isn't it possible to use this
> code by calling the base class's OnPaint and then putting the additional
> drawing code after the call returns ? Or must we redo ALL of the painting
> ourself

> Steve



> > You will need to use an owner drawn button. (Why? Because Bill says
so!!)

> > For your specific example (black square around the text), you will have
to
> > do all the drawing yourself. If you wanted only to change the background
> or
> > text color, you could override CWnd::OnCtlColor().

> > This is not particularly onerous, however, and it gives you complete
> control
> > over the font of your button text, shadows, etc., although don't forget
> that
> > you do have to draw the up, down, disabled, and focus states for your
> > button.

> > When you get to the point that you want to draw that focus rectangle
> around
> > the caption, here is how to draw that dotted line properly:

> >   hPen = ExtCreatePen ( PS_COSMETIC | PS_ALTERNATE,
> >          1, &logBrush,0, NULL) ;

> > HTH
> > Chris Hough



Fri, 18 Jan 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Overriding the OnPaint method for button controls

2. How to force a control's OnPaint Event

3. About override the OnPaint function.

4. About override the OnPaint function!

5. Override OnPaint in ATL/WTL

6. OnPaint override on CListViewCtrl?

7. CListView - Overriding OnPaint()

8. Overriding OnPaint of CListView

9. OnPaint() override

10. CListBox -- Owner Drawn - (override OnPaint) - Need help, please!

11. overriding events (OnPaint, OnClick, etc.)

12. Custom Control 's OnMouseXXX and OnKeyXXX overrides not called

 

 
Powered by phpBB® Forum Software