实现对话框在位图作为背景时的控件透明
2010-09-24 10:00
417 查看
// TransparentDlg.cpp : implementation file // #include "stdafx.h" #include "Transparent.h" #include "TransparentDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CTransparentDlg dialog CTransparentDlg::CTransparentDlg(CWnd* pParent /*=NULL*/) : CDialog(CTransparentDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTransparentDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 } void CTransparentDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTransparentDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CTransparentDlg, CDialog) //{{AFX_MSG_MAP(CTransparentDlg) ON_WM_ERASEBKGND() ON_WM_CTLCOLOR() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CTransparentDlg message handlers BOOL CTransparentDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog // TODO: Add extra initialization here //构建背景位图画刷 CBitmap m_Bitmap; if(m_Bitmap.LoadBitmap(IDB_BKBITMAP)) { m_BkBrush.CreatePatternBrush(&m_Bitmap); } return TRUE; // return TRUE unless you set the focus to a control } //背景直接使用位图画刷填充 BOOL CTransparentDlg::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default CRect rcClient; GetClientRect(rcClient); pDC->FillRect(rcClient, &m_BkBrush); return TRUE; //return CDialog::OnEraseBkgnd(pDC); } HBRUSH CTransparentDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); // TODO: Change any attributes of the DC here // { CRect rcCtrl; pWnd->GetWindowRect( &rcCtrl ); //获取控件位置 ScreenToClient( &rcCtrl ); //转换到对话框 //获取ClientDC CDC *pBkDC = GetDC(); //拷贝背景 pDC->BitBlt(0, 0, rcCtrl.Width(), rcCtrl.Height(), pBkDC, rcCtrl.left, rcCtrl.top, SRCCOPY); //清理工作 ReleaseDC( pBkDC ); //释放ClientDC //添加其他代码 // pDC->SetBkMode(TRANSPARENT); //背景透明模式 hbr = (HBRUSH)GetStockObject(NULL_BRUSH); // } // TODO: Return a different brush if the default is not desired return hbr; }
相关文章推荐
- 实现对话框在位图作为背景时的控件透明
- VC使用位图作为对话框或者控件背景
- [转]引用 VC 对话框设置位图背景并透明控件
- MFC 如何实现对话框添加位图作为背景图
- MFC实现背景透明,控件不透明的对话框,且点击图片有事件响应
- MFC学习之 对话框设置背景颜色及控件透明的方法
- MFC中实现Static控件背景透明
- MFC对话框控件和背景图片自适应窗口最大化和拉伸缩放的实现
- 实现控件透明背景的几种方案
- MFC基于对话框如何添加位图并使位图背景透明(TransparentBlt函数)
- 实现控件背景透明的几种方法
- WM_ERASEBKGND消息及位图背景与透明的实现
- 对话框背景真正起作用的做法。(有内存泄露,不过可以通过各个控件的CtrlColor方法实现)
- 实现控件的透明背景
- VC对话框如何添加WM_ERASEBKGND消息(OnEraseBkgnd函数)及对话框使用位图背景并透明
- VC中设置了对话框背景图片的情况下不能正确显示radio控件透明
- VC对话框使用OnEraseBkgnd函数位图背景并透明
- VC对话框使用OnEraseBkgnd函数位图背景并透明
- React-Native 如何将图片作为页面的背景以及控件的嵌套实现启动应用
- VC对话框使用OnEraseBkgnd函数位图背景并透明