set the text color and the background color of a Control Cbutton 
Author Message
 set the text color and the background color of a Control Cbutton

Hello,
I would like to set the text color and the background color of a Control
Cbutton.
I tried the following code in 'OnCtlColor' but it only works for a CStatic
Control.

HBRUSH CFontesView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
 HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);

 COLORREF crRed = RGB(255,0,0);
 COLORREF crBlue = RGB(128,184,223);

   if (nCtlColor != CTLCOLOR_EDIT && nCtlColor != CTLCOLOR_LISTBOX
  && nCtlColor != CTLCOLOR_BTN)
 {
     pDC->SetBkMode(TRANSPARENT);
  hbr = CreateSolidBrush(crBlue);
   }

 if (pWnd->GetDlgCtrlID() == IDC_BUTTONTEST1)  // Doesn't work ! ! ! !
{
     pDC->SetBkMode(TRANSPARENT);
  pDC->SetTextColor(crRed);
  pDC->SetBkColor(WHITE);
  hbr = CreateSolidBrush(WHITE);
  return (HBRUSH) hbr;
   }

 if (pWnd->GetDlgCtrlID() == IDC_STATIC2)   // ok !!!
 {
  pDC->SetBkMode(TRANSPARENT);
  pDC->SetTextColor(crRed);
  file://pDC->SetBkColor(WHITE);
 }

 return hbr;

Quote:
}

Thanks,
Arnaud from France


Sat, 12 Oct 2002 03:00:00 GMT  
 set the text color and the background color of a Control Cbutton

Quote:
>I would like to set the text color and the background color of a Control
>Cbutton.
>I tried the following code in 'OnCtlColor' but it only works for a CStatic
>Control.

To set the colour for a button you need an owner drawn button. Have a
look at the Platform SDK docs on WM_CTLCOLORBTN.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sat, 12 Oct 2002 03:00:00 GMT  
 set the text color and the background color of a Control Cbutton
Use an owner-draw button. There is an example of a bitmap-based
owner-draw button on my MVP Tips site, and you can work
theme-and-variation on this to draw anything you want.
                                joe

On Tue, 25 Apr 2000 14:14:40 +0200, "Arnaud MASION"

Quote:

>Hello,
>I would like to set the text color and the background color of a Control
>Cbutton.
>I tried the following code in 'OnCtlColor' but it only works for a CStatic
>Control.

>HBRUSH CFontesView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
>{
> HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);

> COLORREF crRed = RGB(255,0,0);
> COLORREF crBlue = RGB(128,184,223);

>   if (nCtlColor != CTLCOLOR_EDIT && nCtlColor != CTLCOLOR_LISTBOX
>  && nCtlColor != CTLCOLOR_BTN)
> {
>     pDC->SetBkMode(TRANSPARENT);
>  hbr = CreateSolidBrush(crBlue);
>   }

> if (pWnd->GetDlgCtrlID() == IDC_BUTTONTEST1)  // Doesn't work ! ! ! !
>{
>     pDC->SetBkMode(TRANSPARENT);
>  pDC->SetTextColor(crRed);
>  pDC->SetBkColor(WHITE);
>  hbr = CreateSolidBrush(WHITE);
>  return (HBRUSH) hbr;
>   }

> if (pWnd->GetDlgCtrlID() == IDC_STATIC2)   // ok !!!
> {
>  pDC->SetBkMode(TRANSPARENT);
>  pDC->SetTextColor(crRed);
>  file://pDC->SetBkColor(WHITE);
> }

> return hbr;

>}

>Thanks,
>Arnaud from France

Joseph M. Newcomer [MVP]

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


Thu, 17 Oct 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Change CButton color and CButton text color in CDialog

2. setting text and background colors for a control

3. Setting background color of a CButton?

4. Change background and text color in CButton

5. Background Color, Text Color

6. Background color and text color in menu

7. Change text color and background color in CEditView

8. Change a part of Background color or a part of text color from CListCtrl

9. Setting the background color of Static Text item and window

10. Setting background & text color

11. Setting text and background color in CEdit

12. how to set text background color

 

 
Powered by phpBB® Forum Software