MFC SDI: How do I create transparent SDI views
来源:互联网 发布:snmp获取linux信息 编辑:程序博客网 时间:2024/06/05 02:06
MFC SDI: How do I create transparent SDI views?
Q: How do I create transparent SDI views?
A: One can make a the view of an MFC application transparent by handling 'CView::OnEraseBkgnd()' function and returning 'FALSE' instead of the default 'CView::OnEraseBkgnd()' call.
But this will not give a real transparent window, since the original view background will be dragged along while moving the application window. To overcome this, I have handled 'OnMove()' and 'OnSize()' functions of 'CMainFrame' class to update the view to reflect the real background, by repainting the view each time the application window is moved / sized.
I have defined a function 'RepaintWindow()' as part of the 'CMainFrame' class and implemented to repaint the view with correct background information.
At present, this is implemented for SDI application. With little modification (for updating all views), this methodology can be extended for MDI applications as well.
A: One can make a the view of an MFC application transparent by handling 'CView::OnEraseBkgnd()' function and returning 'FALSE' instead of the default 'CView::OnEraseBkgnd()' call.
Code:
BOOL CTransparentView::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default return FALSE;// return CView::OnEraseBkgnd(pDC);}
But this will not give a real transparent window, since the original view background will be dragged along while moving the application window. To overcome this, I have handled 'OnMove()' and 'OnSize()' functions of 'CMainFrame' class to update the view to reflect the real background, by repainting the view each time the application window is moved / sized.
Code:
void CMainFrame::OnMove(int x, int y) { CFrameWnd::OnMove(x, y); // TODO: Add your message handler code here RepaintView();}void CMainFrame::OnSize(UINT nType, int cx, int cy) { CFrameWnd::OnSize(nType, cx, cy); // TODO: Add your message handler code here RepaintView();}
I have defined a function 'RepaintWindow()' as part of the 'CMainFrame' class and implemented to repaint the view with correct background information.
Code:
void CMainFrame::RepaintView(){ // Gets current view CView* pView = GetActiveView(); if (pView) // Valid view { // Hides view to get background ShowWindow(SW_HIDE); // Gets desktop device context HDC hDC = ::GetDC(NULL); if (hDC) // Valid device context handle { // Get clients rectangle in screen coordinates CRect Rect; pView->GetClientRect(Rect); pView->ClientToScreen(Rect); // Gets device context for current view CClientDC DC(pView); // Pastes background to view ::BitBlt(DC.m_hDC, 0, 0, Rect.Width(), Rect.Height(), hDC, Rect.left, Rect.top, SRCCOPY); // Releases desktop device context ::ReleaseDC(NULL, hDC); } // Shows view with right background info ShowWindow(SW_SHOW); }}
At present, this is implemented for SDI application. With little modification (for updating all views), this methodology can be extended for MDI applications as well.
- MFC SDI: How do I create transparent SDI views
- SDI
- MFC SDI随笔
- MFC SDI修改标题
- MFC SDI 执行流程
- MFC单文档SDI
- MFC SDI 多视图
- MFC SDI 禁用最大化最小化
- 定制MFC SDI应用程序外观
- How do I create a MEX file
- How do I create my own DTD?
- MFC SDI应用程序的启动顺序
- 在MFC SDI程序中使用SDL
- MFC SDI应用程序的启动顺序
- MFC程序(SDI)一开始运行最大化
- MFC(SDI)开始运行最大化详解
- MFC中SDI中用GDI+显示图片
- 在MFC SDI程序中使用SDL
- Ubuntu 下自由切换JDK版本
- 计算机视觉工业的前途在何方
- 约瑟夫问题
- 树视控件在多文档中地运用
- C#记事本源代码(winFrom)
- MFC SDI: How do I create transparent SDI views
- VC++数据类型转换
- c代码指针2例
- Google十诫(转)
- wince中如何支持sqlce3.0
- DFM文件与XML文件互转
- Linux 动态库剖析
- SQL中系统临时表的使用和禁忌 及 Exec(SQLScript) 的使用
- 用于查询当前数据库中所有表格的记录条数的脚本