MFC控制元件背景透明設定
阿新 • • 發佈:2018-12-12
這種方法只適用於下面這些控制元件
- 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; }