zoukankan      html  css  js  c++  java
  • 终于找到了梦寐以求的Q165073

        不多说了,全文录在这里,我就奇了怪了,为什么在微软网站上都没有这份文章的存档吗?

    INFO: Making Transparent Controls with MFC

    Last reviewed: February 17, 1998
    Article ID: Q165073
    The information in this article applies to:
    • Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0

    SUMMARY

    The OLE Control '96 Specification defines transparent controls and Visual C++ 4.2 will create controls that conform to this new specification. However, most available containers, including Internet Explorer 3.0, do not support this feature. This article demonstrates the process required to convert a standard Visual C++ ControlWizard control to be transparent in Internet Explorer 3.0.

    MORE INFORMATION

    Steps to Create a Transparent OLE Control

    1. Create a default control using the ControlWizard.

    2. Override PreCreateWindow for the control as shown below. You will need to add the prototype and handler manually because ClassWizard does not provide an override for PreCreateWindow in the case of controls:

            BOOL CTransCtrl::PreCreateWindow(CREATESTRUCT& cs)
            {
      
               // Add the Transparent style to the control
               cs.dwExStyle |= WS_EX_TRANSPARENT;
      
               return COleControl::PreCreateWindow(cs);
            }
      
      

    3. To get the control to show what is behind it, use the trick shown below, which sends a WM_ERASEBKGND message to the parent with the handle to the control's device context. Use ClassWizard to add a handler for WM_ERASEBKGND and add the following code:

            BOOL CTransCtrl::OnEraseBkgnd(CDC* pDC)
            {
      
               // This is needed for transparency and the correct drawing...
               CWnd*  pWndParent;       // handle of our parent window
               POINT  pt;
      
               pWndParent = GetParent();
               pt.x       = 0;
               pt.y       = 0;
      
               MapWindowPoints(pWndParent, &pt, 1);
               OffsetWindowOrgEx(pDC->m_hDC, pt.x, pt.y, &pt);
               ::SendMessage(pWndParent->m_hWnd, WM_ERASEBKGND,
                            (WPARAM)pDC->m_hDC, 0);
               SetWindowOrgEx(pDC->m_hDC, pt.x, pt.y, NULL);
      
               return 1;
            }
      
      

    4. Modify the OnDraw() function to display the desired image for the control. The example below draws an ellipse. If you do not select the NULL_BRUSH before drawing, the inside of the ellipse is filled in using the current brush.

      NOTE: If you do not select your own pens and brushes, the resulting behavior is unpredictable and depends on the GDI objects passed by the control container.

            void CTransCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const
      
                                    CRect& rcInvalid)
            {
               CPen* oldpen;  CBrush* oldbrush;
      
               oldpen = (CPen*) pdc->SelectStockObject(BLACK_PEN);
               oldbrush = (CBrush*) pdc->SelectStockObject(NULL_BRUSH);
      
               pdc->Ellipse(rcBounds);
      
               pdc->SelectObject(oldpen);
               pdc->SelectObject(oldbrush);
            }
      
      

    5. Override the OnSetClientSite() function to set the m_bAutoClip member variable to TRUE. The COleControl::m_bAutoClip variable is an undocumented variable that is used to maintain a window that clips the contents of the control to its design-time size:

            void CTransCtrl::OnSetClientSite()
            {
      
               m_bAutoClip = TRUE;
      
               COleControl::OnSetClientSite();
            }
      

  • 相关阅读:
    有哪些带汉字的 LOGO 或者图标设计得很出色?
    从初级晋级高级UI设计师学习路线+全套视频
    UI常见面试题-整体素养篇
    PS精修电影胶片调色特效[附素材及方法]
    全链路UI、UE设计学习路线+视频教程完整版
    网页设计之栅格系统及应用
    移动端APP产品设计结构及专业术语
    九十分钟极速入门Linux——Linux Guide for Developments 学习笔记
    PAT树_层序遍历叶节点、中序建树后序输出、AVL树的根、二叉树路径存在性判定、奇妙的完全二叉搜索树、最小堆路径、文件路由
    数据结构第三部分:树与树的表示、二叉树及其遍历、二叉搜索树、平衡二叉树、堆、哈夫曼树、集合及其运算
  • 原文地址:https://www.cnblogs.com/s5689412/p/192856.html
Copyright © 2011-2022 走看看