MFC控件背景透明设置 - 1

这种方法只适用于下面这些控件
  • 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
// 1. 在对话框的头文件中加入
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);

// 2. 在对话框的cpp文件中加入
BEGIN_MESSAGE_MAP(CtransparentDlg, CDialog)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

HBRUSH CtransparentDlg::OnCtlColor(CDC
* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hBrush
= CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

if(nCtlColor == CTLCOLOR_STATIC)
{
pDC
->SetBkMode(TRANSPARENT);
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
return hBrush;
}
posted @ 2011-05-24 11:24  莫压枯枯地  阅读(9903)  评论(1编辑  收藏  举报