WM_CTLCOLOR 和OnCtlColor

来源:互联网 发布:安卓 安装 linux 编辑:程序博客网 时间:2024/05/19 01:30

  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;   }


判断之后,返回相应的画刷句柄即可实现。

原创粉丝点击