Change CButton color and CButton text color in CDialog 
Author Message
 Change CButton color and CButton text color in CDialog

I'm trying this but it launch an Unknow Software Exception

HBRUSH CThreadsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (nCtlColor == CTLCOLOR_BTN )
{

pDC->SetTextColor(RGB(0,255,0));
pDC->SetBkColor(RGB(0,0,255))
m_Brush.CreateSolidBrush(RGB(0,0,255));
return (HBRUSH)m_Brush.GetSafeHandle();

Quote:
}
return hbr;
}

Other question:
This method work fine with CStatic controls, but ?How can I change color for
a CProgressCrtl?

Thanks in advance.

--

Rodrigo Corral Gonzlez



Sun, 07 Dec 2003 03:58:37 GMT  
 Change CButton color and CButton text color in CDialog
There are few things to note here.

According to your subject, you seem want to change CButton color. OnCtlColor
is not the way to go. You have to owner draw the button. There are several
examples in button control section at www.codeguru.com.

In addition, you are leaking brush here. You are creating a new brush each
time OnCtlColor is called. Eventually you will run out of memory. You should
create it outside this method (perhaps in OnInitDialog) and simply return
the brush handle when needed.

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.



Quote:
> I'm trying this but it launch an Unknow Software Exception

> HBRUSH CThreadsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
> {
> HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
> if (nCtlColor == CTLCOLOR_BTN )
> {

> pDC->SetTextColor(RGB(0,255,0));
> pDC->SetBkColor(RGB(0,0,255))
> m_Brush.CreateSolidBrush(RGB(0,0,255));
> return (HBRUSH)m_Brush.GetSafeHandle();

> }
> return hbr;
> }

> Other question:
> This method work fine with CStatic controls, but ?How can I change color
for
> a CProgressCrtl?

> Thanks in advance.

> --

> Rodrigo Corral Gonzlez




Sun, 07 Dec 2003 04:11:07 GMT  
 Change CButton color and CButton text color in CDialog
If you want to use OnCtlColor (which as has already been pointed out,
is exactly the wrong thing for a CButton), you should use a
"reflected" message. Subclass the control whose background you want to
change, make a handler for =WM_CTLCOLOR (note the = in front!), and
you don't need to test for anything because only that control will get
the request. Create the brush in the constructor for the class, and
free it in the destructor of the class.
                        joe



Quote:
>There are few things to note here.

>According to your subject, you seem want to change CButton color. OnCtlColor
>is not the way to go. You have to owner draw the button. There are several
>examples in button control section at www.codeguru.com.

>In addition, you are leaking brush here. You are creating a new brush each
>time OnCtlColor is called. Eventually you will run out of memory. You should
>create it outside this method (perhaps in OnInitDialog) and simply return
>the brush handle when needed.

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Mon, 08 Dec 2003 02:33:14 GMT  
 Change CButton color and CButton text color in CDialog

Quote:
>make a handler for =WM_CTLCOLOR (note the = in front!),

Wow!

--
Ajay Kalra [MVP - VC++]

Note: Please post all replies to newsgroup only.



Quote:
> If you want to use OnCtlColor (which as has already been pointed out,
> is exactly the wrong thing for a CButton), you should use a
> "reflected" message. Subclass the control whose background you want to
> change, make a handler for =WM_CTLCOLOR (note the = in front!), and
> you don't need to test for anything because only that control will get
> the request. Create the brush in the constructor for the class, and
> free it in the destructor of the class.
> joe



> >There are few things to note here.

> >According to your subject, you seem want to change CButton color.
OnCtlColor
> >is not the way to go. You have to owner draw the button. There are
several
> >examples in button control section at www.codeguru.com.

> >In addition, you are leaking brush here. You are creating a new brush
each
> >time OnCtlColor is called. Eventually you will run out of memory. You
should
> >create it outside this method (perhaps in OnInitDialog) and simply return
> >the brush handle when needed.

> Joseph M. Newcomer [MVP]

> Web: http://www3.pgh.net/~newcomer
> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Mon, 08 Dec 2003 02:41:50 GMT  
 Change CButton color and CButton text color in CDialog
Yeah, it makes like a WHOLE lot simpler, by putting the control down
in the subclass where it always belonged. The only time I ever write a
top-level handler for anything is for menus.
                        joe



Quote:
>>make a handler for =WM_CTLCOLOR (note the = in front!),

>Wow!

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Mon, 08 Dec 2003 09:45:23 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. set the text color and the background color of a Control Cbutton

2. Change background and text color in CButton

3. Change Text color in CButton?

4. Change Color of CButton, CEdit and so on

5. how do I change the color of CButton???

6. Change background color of CButton

7. CButton Change color of disabled radio button

8. How can I change color of CButton

9. How to change the color of a CButton

10. Change the color on CButton ?

11. How do you change CButton color???

12. Changing color of a 'CButton button'

 

 
Powered by phpBB® Forum Software