描述:
我想把MFC ActiveX做成窗口样式,在IE调用ActiveX后窗口能显示在IE里
解决方案1:
需要设置一下窗口的类型
解决方案2: 从codeguru 借来的,我尝试过没问题。
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.
Create a new MFC ActiveX ControlWizard workspace (no need to special options).
Insert a new dialog resource named IDC_MYDIALOG (check following: style - child, border - dialog frame, visible, control, static edge)
Insert a new MFC class named CMyDialog (base class CDialog)
Add CMyDialog m_MyDialog member to your CDialogCtrl header source (don't forget to add #include "MyDialog.h")
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>
派生窗口的属性设为弹出型就可以了萨
解决方案4: 一、引入Dialog技术
---- 下面介绍在制作ActiveX控件时引入有模式对话框技术,制作步骤如下:
创建一新的MFC ActiveX ControlWizard项目,取名为Hello,其他用缺省选项;
在ResourceView页中新增一对话框资源,命名为IDD_HELLODIALOG,可以在对话
框上放自己的控件;
为对话框资源IDD_HELLODIALOG创建新类CHelloDialog,从CDialog继承;
确认在HelloCtrl.h中已加入语句#include "HelloDialog.h",为CHelloCtrl类
添加成员变量CHelloDialog m_helloDialog;
用ClassWizard在Automation页中为CHelloCtrl添加一方法void DoHello(),外
部名亦为DoHello;
void CHelloCtrl::DoHello()
{
// 显示对话框
m_helloDialog.DoModal();
}
---- 可以用ActiveX Control Test Container测试Hello Control的DoHello方法。
---- 下面介绍在制作ActiveX控件时引入无模式对话框技术,制作步骤如下:
在上面工作的基础上,用ClassWizard为CHelloCtrl添加WM_CREATE的处理函数
OnCreate,在此创建无模式对话框;
修改DoHello代码,在此显示对话框;
int CHelloCtrl::OnCreate
(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// 创建对话框
m_helloDialog.Create(IDD_HELLODIALOG);
return 0;
}
void CHelloCtrl::DoHello()
{
// 显示对话框
m_helloDialog.ShowWindow(SW_SHOW);
}
---- 下面介绍制作以对话框作为界面的ActiveX控件技术,制作步骤如下:
在上面工作的基础上,设置对话框资源IDD_HELLODIALOG属性的Style页为
Style:Child、Border:Dialog Frame、Title Bar:unchecked;设置More Style
页为Visible:checked;Control:checked;设置Extended Styles页为
Static Edge:checked;
在CHelloCtrl::OnCreate中写入m_helloDialog.Create(IDD_HELLODIALOG,this)语句;
在CHelloCtrl::OnDraw中写入m_helloDialog.MoveWindow(rcBounds,TRUE);
int CHelloCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// 创建对话框
m_helloDialog.Create(IDD_HELLODIALOG,this);
return 0;
}
void CHelloCtrl::OnDraw(CDC* pdc, const
CRect& rcBounds, const CRect& rcInvalid)
{
// 定位Hello对话框
m_helloDialog.MoveWindow(rcBounds,TRUE);
}
---- 二、引入FormView技术
---- 下面介绍在制作ActiveX控件时引入FormView技术,制作步骤如下:
在上面工作的基础上,在ResourceView页中新增一对话框资源,命名为
IDD_HELLOFORMVIEW,可以在对话框上放自己的控件;
设置对话框资源IDD_HELLODIALOG属性的Style页为Style:Child、
Border:Dialog Frame、Title Bar:unchecked;设置More Style页为
Visible:checked;Control:checked;设置Extended Styles页为Static Edge:checked;
为对话框资源IDD_HELLOFORMVIEW创建新类CHelloFormView,从CFormView继承;
在HelloFormView.h中将CHelloFormView的构造函数CHelloFormView()和析
构函数virtual ~CHelloFormView()从protected改为public;
在HelloFormView.h中对CHelloFormView类加入public friend class CHelloCtrl;
确认在HelloCtrl.h中已加入语句#include "HelloFormView.h",为CHelloCtrl类
添加成员变量CHelloFormView m_helloFormView;
修改CHelloCtrl::OnCreate函数,在此创建m_helloFormView;
修改DoHello代码,在此显示FormView;
int CHelloCtrl::OnCreate
(LPCREATESTRUCT lpCreateStruct)
{
if (COleControl::OnCreate(lpCreateStruct) == -1)
return -1;
// 创建FormView
m_helloFormView.Create(NULL,NULL,AFX_WS_DEFAULT_VIEW,
CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL);
return 0;
}
void CHelloCtrl::OnDraw(CDC* pdc, const
CRect& rcBounds, const CRect& rcInvalid)
{
// 定位Hello对话框
m_helloFormView.MoveWindow(rcBounds,TRUE);
}