OnCtrlColor - how do I set a button fore color?
-
Hi, I'm about to spontaneously combust if I can't manage to set the color of one single little button in a dialog. It seems that with OnCtlColor() I can set the color of EVERYTHING EXCEPT my button's foreground. Please help me before I blow! :confused: I know I am missing something probably very simple. Do I need to use OnDrawItem()? Thank you for any suggestions. I am relatively new (1 year) to MFC so be kind and if possible detailed in your suggestions. Thank you so much. Here's one of several bits of code I have tried :- //CBrush is set within OnInitDialog() m_brush.CreateSolidBrush(RGB(0,0,255)); // Blue brush .... HBRUSH CTry_button_colorsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); //this works ok - my editbox ends up a nice blue color if (nCtlColor == CTLCOLOR_EDIT || nCtlColor == CTLCOLOR_MSGBOX ) { pDC->SelectObject(m_brush); hbr = this->m_brush; } //THIS DOES NOT WORK if (nCtlColor == CTLCOLOR_BTN) { hbr = this->m_brush; pDC->SetBkColor(RGB(0,0,255)); } //THIS DOESN'T WORK EITHER if( pWnd->GetDlgCtrlID() == IDC_MYBUTTON) { pDC->SetBkColor(RGB(0,0,255)); pDC->SelectStockObject(WHITE_BRUSH); } return hbr; } Michael
-
Hi, I'm about to spontaneously combust if I can't manage to set the color of one single little button in a dialog. It seems that with OnCtlColor() I can set the color of EVERYTHING EXCEPT my button's foreground. Please help me before I blow! :confused: I know I am missing something probably very simple. Do I need to use OnDrawItem()? Thank you for any suggestions. I am relatively new (1 year) to MFC so be kind and if possible detailed in your suggestions. Thank you so much. Here's one of several bits of code I have tried :- //CBrush is set within OnInitDialog() m_brush.CreateSolidBrush(RGB(0,0,255)); // Blue brush .... HBRUSH CTry_button_colorsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); //this works ok - my editbox ends up a nice blue color if (nCtlColor == CTLCOLOR_EDIT || nCtlColor == CTLCOLOR_MSGBOX ) { pDC->SelectObject(m_brush); hbr = this->m_brush; } //THIS DOES NOT WORK if (nCtlColor == CTLCOLOR_BTN) { hbr = this->m_brush; pDC->SetBkColor(RGB(0,0,255)); } //THIS DOESN'T WORK EITHER if( pWnd->GetDlgCtrlID() == IDC_MYBUTTON) { pDC->SetBkColor(RGB(0,0,255)); pDC->SelectStockObject(WHITE_BRUSH); } return hbr; } Michael
You can't change the button colour using
OnCtlColor()
. You'll have to create an owner-draw button to do this. michael thomas wrote: I'm about to spontaneously combust Don't spend too much time in the sun then... ;PRyan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
-
Hi, I'm about to spontaneously combust if I can't manage to set the color of one single little button in a dialog. It seems that with OnCtlColor() I can set the color of EVERYTHING EXCEPT my button's foreground. Please help me before I blow! :confused: I know I am missing something probably very simple. Do I need to use OnDrawItem()? Thank you for any suggestions. I am relatively new (1 year) to MFC so be kind and if possible detailed in your suggestions. Thank you so much. Here's one of several bits of code I have tried :- //CBrush is set within OnInitDialog() m_brush.CreateSolidBrush(RGB(0,0,255)); // Blue brush .... HBRUSH CTry_button_colorsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); //this works ok - my editbox ends up a nice blue color if (nCtlColor == CTLCOLOR_EDIT || nCtlColor == CTLCOLOR_MSGBOX ) { pDC->SelectObject(m_brush); hbr = this->m_brush; } //THIS DOES NOT WORK if (nCtlColor == CTLCOLOR_BTN) { hbr = this->m_brush; pDC->SetBkColor(RGB(0,0,255)); } //THIS DOESN'T WORK EITHER if( pWnd->GetDlgCtrlID() == IDC_MYBUTTON) { pDC->SetBkColor(RGB(0,0,255)); pDC->SelectStockObject(WHITE_BRUSH); } return hbr; } Michael
If you want to change the color of a dialog button, you have to use owner-draw button. (you can use bitmap buttons) Changing the color through OnCtlColor() will not work for buttons. The following Knowledge Base articles may be of help to you: ID: Q32685 TITLE: Using the WM_CTLCOLOR Message ID: Q64328 SAMPLE: Owner-Draw: 3-D Push Button Made from Bitmaps with Text HPS HwndSpy - GUI developer's aid to visually locate and inspect windows. For the month of August only, use coupon code CP-81239 for 30% off.
-
You can't change the button colour using
OnCtlColor()
. You'll have to create an owner-draw button to do this. michael thomas wrote: I'm about to spontaneously combust Don't spend too much time in the sun then... ;PRyan
"Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
Thanks Ryan.
-
If you want to change the color of a dialog button, you have to use owner-draw button. (you can use bitmap buttons) Changing the color through OnCtlColor() will not work for buttons. The following Knowledge Base articles may be of help to you: ID: Q32685 TITLE: Using the WM_CTLCOLOR Message ID: Q64328 SAMPLE: Owner-Draw: 3-D Push Button Made from Bitmaps with Text HPS HwndSpy - GUI developer's aid to visually locate and inspect windows. For the month of August only, use coupon code CP-81239 for 30% off.
Thanks for the help. Michael