终于找到了梦寐以求的Q165073
2005-07-14 16:11
267 查看
不多说了,全文录在这里,我就奇了怪了,为什么在微软网站上都没有这份文章的存档吗?
INFO: Making Transparent Controls with MFCLast reviewed: February 17, 1998Article ID: Q165073 |
The information in this article applies to: Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0 SUMMARYThe 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 INFORMATIONSteps to Create a Transparent OLE ControlCreate a default control using the ControlWizard.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) { [code]// Add the Transparent style to the control cs.dwExStyle |= WS_EX_TRANSPARENT; return COleControl::PreCreateWindow(cs); } [/code] 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) { [code]// 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; } [/code] 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 [code]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); } [/code] 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() { [code]m_bAutoClip = TRUE; COleControl::OnSetClientSite(); } [/code] |
相关文章推荐
- 研究了一下午,终于找到了把框架中的立体分割线变成平面的方法了(去除三维效果)
- 菜鸟蹒跚学ASP-转帖一个HTA的代码,终于找到VBS和JS的UI了。
- 找了好久,有关计算机的社区网站 终于找到了!
- 终于找到了一本PYTHON的中文书籍
- 我的技术博客终于找到一个好地方重新开张了~
- 终于找到一个功能全面的番茄钟时间管理工具:myPomodoro for Mac
- 终于找到I18N了,居然改名字叫ICU了(或许好久没有用到忘记了)
- 历经4个月的奋战,终于找到一本好书
- 折磨半个月终于找到php脚本所谓的“内存泄露”原因!
- 终于找到了归属感了,在充满技术气息的环境里呼吸就是感到畅然阿Mar26th2007
- C#初学者——终于奋战一个月找到了自己心意的工作
- 终于找到一个写日记的地方了
- 终于在visual studio.net 2005 找到了创建 XML Web services 的项目的方法
- 最近帮公司开发一个邮件营销软件 用到XPTable 但找了很多方法 摸索了很久都不知道如何更新进度条 不过在国外的一个网站 终于找到答案了
- jquery 一个checkbox全选与反选(找了很久,终于找到了)
- 终于找到了曲子
- 在eclipse的wtp版本中不编译jsp的方法,今天终于找到了
- Javascript:郁闷了好久终于找到原因了,原理还不明白
- 终于找到问题所在,javabean引用问题