MFC基于对话框的ActiveX

原文地址: http://www.vckbase.com/english/code/atl/dialogctrl.shtml.htm


This article was contributed by Petr Stejskal.

I wanted to create a control which would behave as a dialog or formview (you can place controls here). There is a simple way to do it - to take advantage of ActiveX.

  1. Create a new MFC ActiveX ControlWizard workspace (no need to special options).
  2. Insert a new dialog resource named IDC_MYDIALOG (check following: style - child, border - dialog frame, visible, control, static edge)
  3. Insert a new MFC class named CMyDialog (base class CDialog)
  4. Add CMyDialog m_MyDialog member to your CDialogCtrl header source (don't forget to add #include "MyDialog.h")
  5. Using classwizard add a member function OnCreate (WM_CREATE)
int CDialogCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct) 

{
    if (COleControl::OnCreate(lpCreateStruct) == -1)
        return -1;

    m_MyDialog.Create(IDD_MYDIALOG, this);
    return 0;
}

Modify the member function OnDraw (the dialog's size depends on the WIDTH and HEIGHT specified in the HTML file):

void CDialogCtrl::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
   // TODO: Replace the following code with your own drawing code.
   // pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
   // pdc->Ellipse(rcBounds);

   m_MyDialog.MoveWindow(rcBounds, TRUE);
}

To show the control in your browser use this simple HTML:

  <html>
  <head>
  <title>DialogControl</title>
  </head>
  <body>
  
  <center>
  <OBJECT ID="DialogControl"  CLASSID="CLSID:insert here the GUID from ODL file"
   HEIGHT=300 WIDTH=300>
  </OBJECT>
  </center>
  
  </body>
  </html>



注释:
insert here the GUID from ODL file即*.odl中的
//  Class information for ×××××下面的数字
DialogControl名字可任意
OBJECT ID="xx"  CLASSID="CLSID:7446B57B-F6FD-4781-B74A-84E11ED3EE44"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值