About OnCtlColor
-
I want a button to diplay the red text sometime, so I create a class derived from CButton and override the OnCtlColor handler, as below: HBRUSH CColorButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor); if(m_iFlag == 1) pDC->SetTextColor(0x000000ff); return hbr; } but I found the handler didn't be executed even when the dialog initialized, How can I do the work I want. Thanx.
-
I want a button to diplay the red text sometime, so I create a class derived from CButton and override the OnCtlColor handler, as below: HBRUSH CColorButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor); if(m_iFlag == 1) pDC->SetTextColor(0x000000ff); return hbr; } but I found the handler didn't be executed even when the dialog initialized, How can I do the work I want. Thanx.
This does not answer your question, but it may solve your problem: check Yury Goltsman's article Colored/Blinking Controls and Dialogs with any Font [^]. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
This does not answer your question, but it may solve your problem: check Yury Goltsman's article Colored/Blinking Controls and Dialogs with any Font [^]. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
I want a button to diplay the red text sometime, so I create a class derived from CButton and override the OnCtlColor handler, as below: HBRUSH CColorButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor); if(m_iFlag == 1) pDC->SetTextColor(0x000000ff); return hbr; } but I found the handler didn't be executed even when the dialog initialized, How can I do the work I want. Thanx.
Are you using
ON_WM_CTLCOLOR()
orON_WM_CTLCOLOR_REFLECT()
in your message map? Since yourOnCtlColor()
function is in your button, you need to useON_WM_CTLCOLOR_REFLECT()
. If you're not, just replace the message map entry and it will work fine. Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
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" -
Are you using
ON_WM_CTLCOLOR()
orON_WM_CTLCOLOR_REFLECT()
in your message map? Since yourOnCtlColor()
function is in your button, you need to useON_WM_CTLCOLOR_REFLECT()
. If you're not, just replace the message map entry and it will work fine. Hope this helps, Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
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"Yeth, I also found that is the point just now. It seems that the ON_WM_CTLCOLOR message could only be managed by parent wnd, I replaced it with ON_WM_CTLCOLOR_REFLECT and overrided CtlColor() (not OnCtlColor) and it worked. Thank you. Does it means only I need is to manage the ON_WM_CTLCOLOR_REFLECT message but ON_WM_CTLCOLOR?
-
Yeth, I also found that is the point just now. It seems that the ON_WM_CTLCOLOR message could only be managed by parent wnd, I replaced it with ON_WM_CTLCOLOR_REFLECT and overrided CtlColor() (not OnCtlColor) and it worked. Thank you. Does it means only I need is to manage the ON_WM_CTLCOLOR_REFLECT message but ON_WM_CTLCOLOR?
You don't need
ON_WM_CTLCOLOR()
, onlyON_WM_CTLCOLOR_REFLECT()
Ryan Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
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" -
I want a button to diplay the red text sometime, so I create a class derived from CButton and override the OnCtlColor handler, as below: HBRUSH CColorButton::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CButton::OnCtlColor(pDC, pWnd, nCtlColor); if(m_iFlag == 1) pDC->SetTextColor(0x000000ff); return hbr; } but I found the handler didn't be executed even when the dialog initialized, How can I do the work I want. Thanx.
Olinn
Have a look at the msdn article Visual C++/MFC Frequently Asked Questions__, in the MSDN library. I haven't got the web link, but the extract is shown below:How do I change the background color of a button? Note: the method in "How do I change the background color of a control?" will not work for buttons! If you want to change the color of a dialog button, you have to use an 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: Q32685, "Using the WM_CTLCOLOR Message," and Q64328, "SAMPLE: Owner-Draw: 3-D Push Button Made from Bitmaps with Text." This article explains sample code for a owner-draw button. Ramesh (NetQuest), MSMFC, 8/3/95
"..Even my comments have bugs!"
Inspired by Toni78__