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_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
对比颜色类型。
判断之后,返回相应的画刷句柄即可实现。if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC) { // Set the text color to red pDC->SetTextColor(RGB(255, 0, 0)); pDC->SetBkMode(TRANSPARENT); hbr = m_brush; }