about dialog color?
-
hi:i create a dialog such as CMyDlg, i define a variable :CBrush m_brush, then i in onInitDialog :m_brush.CreateSolidBrush(RGB(255,255,0)) then HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetDlgCtrlID() == IDC_STATIC) {// Set the text color to red pDC->SetTextColor(RGB(255, 0, 0)); // Set the background mode for text to transparent pDC->SetBkMode(TRANSPARENT); // Return handle to our CBrush object hbr = m_brush; } return hbr; } but the text color is not i expected,and at the back of the text ,always exist white ?how to modify?but if i do these work in main dialog ,all is ok.
-
hi:i create a dialog such as CMyDlg, i define a variable :CBrush m_brush, then i in onInitDialog :m_brush.CreateSolidBrush(RGB(255,255,0)) then HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); if (pWnd->GetDlgCtrlID() == IDC_STATIC) {// Set the text color to red pDC->SetTextColor(RGB(255, 0, 0)); // Set the background mode for text to transparent pDC->SetBkMode(TRANSPARENT); // Return handle to our CBrush object hbr = m_brush; } return hbr; } but the text color is not i expected,and at the back of the text ,always exist white ?how to modify?but if i do these work in main dialog ,all is ok.
Seems brushing is ok, so it should work. Though I want to point out two things; 1) Do not use pWnd->GetDlgCtrlID() == IDC_STATIC condition unless you assign a unique id to a static control (e.g. IDC_MYSTATIC). Instead, if you want to consider all the static controls, test against nCtlColor == CTLCOLOR_STATIC. 2) Why not to set the text color; pDC->SetTextColor( some rgb );
-- ===== Arman