《MFC中如何使static控件背景透明.docx》由会员分享,可在线阅读,更多相关《MFC中如何使static控件背景透明.docx(2页珍藏版)》请在三一办公上搜索。
1、MFC中如何使static控件背景透明 A.先在头文件*Dlg.h中“/AFX_MSG”之前中添加 afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); B.在源文件*Dlg.cpp中的消息映射入口缴入 BEGIN_MESSAGE_MAP(*Dlg, CDialog) ON_WM_CTLCOLOR /AFX_MSG_MAP END_MESSAGE_MAP 然后添加函数: HBRUSH *Dlg:OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) HBRUSH hBrush
2、= CDialog:OnCtlColor(pDC, pWnd, nCtlColor); if(nCtlColor = CTLCOLOR_STATIC) pDC-SetBkMode(TRANSPARENT); return (HBRUSH):GetStockObject(NULL_BRUSH); returnhBrush; / 或者在HBRUSH CtransparentDlg:OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)中加 switch(pWnd-GetDlgCtrlID) default: pDC-SetBkMode(TRANSPARENT); return (HBRUSH)GetStockObject(NULL_BRUSH); break; 经过处理,如静态文本等控件已经可以实现透明 / switch(pWnd-nID) case ID_YOU_STATIC_ID1: case ID_YOU_STATIC_ID2: case ID_YOU_STATIC_ID3 . pDc-SetBkMode(TRANSPARENT); pDc-SetBkColor(RGB(red,green,blue);