在MFC中实现Static标签实现背景透明

来源:互联网 发布:2017年淘宝怎么刷销量 编辑:程序博客网 时间:2024/05/08 03:27

最近做一个VC++  MFC  的项目,在窗体上实现Static标签背景透明的效果,从网上找了一段,虽然不明白是怎么实现,但是成功了!

以下就是实现的代码

首先在对话框的头文件(.h)中加上函数定义:

afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);


然后在对话框的cpp文件中加入消息:

..........

ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()


最后在在对话框的cpp文件加入函数的实现:

HBRUSH CmyxxxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 

HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); 


// TODO: Change any attributes of the DC here 
switch(pWnd->GetDlgCtrlID()) 

case IDC_STATIC1: 
pDC->SetBkMode(TRANSPARENT); 
pDC->SetTextColor(RGB(0,0,0)); 
return (HBRUSH)GetStockObject(HOLLOW_BRUSH); 
default: 
break; 



// TODO: Return a different brush if the default is not desired 
return hbr; 
}


好了,现在执行,一切OK;

0 0
原创粉丝点击