How to change background color of CDialog and it's elements
-
Hello all How do one should go about changing the background color of CDialog and its elements like buttons,group boxes etc. Pls help me with an example. Many thanks for your help. Hari.
-
Hello all How do one should go about changing the background color of CDialog and its elements like buttons,group boxes etc. Pls help me with an example. Many thanks for your help. Hari.
hy, try to overwrite OnEraseBkg, and also OnCTLColor try something like this: HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { switch (nCtlColor) { case CTLCOLOR_STATIC: case CTLCOLOR_LISTBOX: case CTLCOLOR_BTN: pDC->SetBkColor(GetSysColor(COLOR_BTNFACE)); return (HBRUSH)m_grayBrushPtr->GetSafeHandle(); break; default: return CFormView::OnCtlColor(pDC, pWnd, nCtlColor); break; } }
-
hy, try to overwrite OnEraseBkg, and also OnCTLColor try something like this: HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { switch (nCtlColor) { case CTLCOLOR_STATIC: case CTLCOLOR_LISTBOX: case CTLCOLOR_BTN: pDC->SetBkColor(GetSysColor(COLOR_BTNFACE)); return (HBRUSH)m_grayBrushPtr->GetSafeHandle(); break; default: return CFormView::OnCtlColor(pDC, pWnd, nCtlColor); break; } }
there is an easy was aswell take a variable of type CBrush at class level like CBrush m_Bursh; initiate it in OnInitDialog like m_Bursh.CreateSolidBrush(RGB(0,0,0));//OR ANY OTHER COLOR u WANT override the WM_CTCOLOR message handler and add this line to its implemention HBRUSH CBaseView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { return m_Brush; }