WM_CTLCOLOR 小子以及OnCtlColor响应函数,帮助我们可以灵活的设置对话框以及空间的颜色。
函数的原型如下
afx_msg HBRUSH OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor );
通过pWnd->GetDlgItemID() 对比ID,判断是不是我们需要设置的控件。
-
nCtlColor
-
Contains one of the following values, specifying the type of control:
CTLCOLOR_BTNButton control
CTLCOLOR_DLGDialog box
CTLCOLOR_EDITEdit control
CTLCOLOR_LISTBOXList-box control
CTLCOLOR_MSGBOXMessage box
CTLCOLOR_SCROLLBARScroll-bar control
-
CTLCOLOR_STATICStatic control
对比颜色类型。
if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
{
// Set the text color to red
pDC->SetTextColor(RGB(255, 0, 0));
pDC->SetBkMode(TRANSPARENT);
hbr = m_brush;
}
判断之后,返回相应的画刷句柄即可实现。