3

I am trying to change background color of static text in our project. We use BCG library also.

In h. file I have

afx_msg HBRUSH CtlColor(CDC * pDC, CWnd * pWnd, UINT nCtlColor);
COLORREF m_bckNewsClr;

In cpp. I have:

m_bckNewsClr = RGB(255, 255, 255);

HBRUSH CStartPage::CtlColor(CDC * pDC, CWnd * pWnd, UINT nCtlColor)
{
    pWnd->GetDlgItem(IDC_STATIC_NEWS_CAPTION_1);
    pDC->SetBkColor(m_bckNewsClr);
    return (HBRUSH)m_Brush.GetSafeHandle();
}

In massage map:

ON_WM_CTLCOLOR()

Anyway, it is even not visible the function CtlColor, when I put the breakpoint.

Does someone know how to change this backgound static text in this case?

harper
  • 13,345
  • 8
  • 56
  • 105
Karol
  • 31
  • 4
  • 1
    You can use Spy++ (if x64 target platform: Spy++ 64) to discover if the message is really `WM_CTLCOLOR` . I suspect in the specific case is `WM_CTLCOLORSTATIC` . Some more guidance on https://stackoverflow.com/a/43120662/383779 – sergiol Nov 14 '17 at 15:09
  • 1
    `ON_WM_CTLCOLOR` redirects the message to **On**CtlColor – Barmak Shemirani Nov 14 '17 at 18:00

1 Answers1

3

The ON_WM_CTLCOLOR expects a method named:

afx_msg HBRUSH OnCtlColor(
   CDC* pDC,
   CWnd* pWnd,
   UINT nCtlColor 
);

See also CWnd::OnCtlColor for a sample how to do it.

And also https://stackoverflow.com/a/12007350/8918119

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
Mihayl
  • 3,821
  • 2
  • 13
  • 32