What is the best way to update the background color of one or more static/edit control in a dialog box? For example, I have a static control in a dialog box that I use to depict font color. If the user sets the font to have green color, than the user will see a static control that is green. Initially, I use WM_CTLCOLOR to update the color of the static control. The problem is it only works when the dialog first initializes. Once it has been initialized, I cannot figure out how to update the static control after the user have selected a different color. I try PostMessage(WM_CTLCOLOR, 0, 0), however, the program crashes. It seems ON_WM_CTLCOLOR only works when the dialog is initialized.
Here is the code.
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
HBRUSH hbr = CPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_STATICCOLOR)
// m_pBrush is a pointer to a brush object I use containing the
// font color I the user wants
if (m_pBrush != NULL)
m_pBrush = NULL;
m_pBrush = new CBrush(m_Color);
hbr = static_cast<HBRUSH>(m_pBrush->GetSafeHandle());
Please post if you have any idea on a possible solution.