The WM_CTLCOLOR message has been replaced by more specific notifications in 32-bit versions of Windows. These replacements include the following: WM_CTLCOLORBTN WM_CTLCOLOREDIT WM_CTLCOLORDLG WM_CTLCOLORLISTBOX WM_CTLCOLORSCROLLBAR WM_CTLCOLORSTATIC 要改Static的话,建议用WM_CTLCOLORSTATIC,或者自己继承一个Static,然后写OnPaint
HBRUSH CTest6Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); switch(nCtlColor) { case CTLCOLOR_STATIC: if(pWnd->GetDlgCtrlID() == IDC_STATIC2) { if(GetFocus() == (CStatic*)GetDlgItem(IDC_STATIC2)) { static HBRUSH hbrEdit = ::CreateSolidBrush( RGB(255, 255, 255) ); pDC->SetBkColor(TRANSPARENT); pDC->SetTextColor( RGB(255, 0, 0) ); return hbrEdit; } } } // TODO: Return a different brush if the default is not desired return hbr; }
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// set edit properities
if(pWnd->GetDlgCtrlID() == IDC_EDIT_LOG)
{
static HBRUSH hbrEdit = ::CreateSolidBrush(RGB(255, 255, 255));
pDC->SetBkColor(RGB(255, 255, 255));
pDC->SetTextColor(RGB(0, 0, 255));
return hbrEdit;
}
return hbr;
} // end of OnCtlColor()
WM_CTLCOLORBTN
WM_CTLCOLOREDIT
WM_CTLCOLORDLG
WM_CTLCOLORLISTBOX
WM_CTLCOLORSCROLLBAR
WM_CTLCOLORSTATIC 要改Static的话,建议用WM_CTLCOLORSTATIC,或者自己继承一个Static,然后写OnPaint
{ HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor)
{
case CTLCOLOR_STATIC:
if(pWnd->GetDlgCtrlID() == IDC_STATIC2)
{
if(GetFocus() == (CStatic*)GetDlgItem(IDC_STATIC2))
{
static HBRUSH hbrEdit = ::CreateSolidBrush( RGB(255, 255, 255) );
pDC->SetBkColor(TRANSPARENT);
pDC->SetTextColor( RGB(255, 0, 0) );
return hbrEdit;
}
}
} // TODO: Return a different brush if the default is not desired
return hbr;
}