1).h文件中加入:
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
2).c文件中加入
ON_WM_CTLCOLOR()宏
定义函数
HBRUSH CPCServerDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor)
{
case CTLCOLOR_STATIC:
pDC->SetBkColor(RGB(255, 255, 0));
hbr = CreateSolidBrush(RGB(255, 255, 0));
break;
}
return hbr;
}
3)其他控件如下:
CTLCOLOR_BTN Button control
CTLCOLOR_DLG Dialog box
CTLCOLOR_EDIT Edit control
CTLCOLOR_LISTBOX List-box control
CTLCOLOR_MSGBOX Message box
CTLCOLOR_SCROLLBAR Scroll-bar control
CTLCOLOR_STATIC Static control
记住:单选,多选按钮的文字以及readonly,disable的文本框都算CTLCOLOR_STATIC