编写IE的ActiveX控件 (基础篇)

先来张效果图: 

编写IE的ActiveX控件 (基础篇)_第1张图片



开篇:


环境: Win7 64Bit           VS2010     IE 8    


VS创建一个" MFC ActiveX控件 " 工程,

命名后,一直下一步,然后如下选择: 

编写IE的ActiveX控件 (基础篇)_第2张图片


在项目属性中,选择: 在静态库中使用 MFC


插入一个Dialog,在Dialog上创建一个静态文本框,写上自己想要的文字

并将此对话框创建相应的类,如: CMyDlg


在工程中的 Ctrl类中,新建一个成员变量: CMyDlg m_dlgMy;

并将Ctrl类添加一个OnCreate事件

在OnCreate中添加:

m_dlgMy.Create(IDD_DLG_TEST, this);

以创建此对话框....  差点忘了,这个对话框的属性要修改一下:

Visible: True   Border:None     Style:Child


编译后(Debug/Releasd?), Win+R CMD  对控件进行注册: 

regsvr32    路径.ocx        (路径....拖入cmd中即可~)


还要下载这个: 

Microsoft ActiveX Control Pad

http://msdn.microsoft.com/en-us/library/ms968493.aspx


以兼容性 XP 模式安装

Microsoft ActiveX Control Pad

中,新建一个 HTML,然后插入已注册的OCX, 保存成网页, 然后用IE打开此网页, 允许ActiveX 即可~


===================================================
其它:

基础:VS2010创建ActiveX控件(1)



http://hi.baidu.com/yulinxx_/item/0e88bb1ec51d83fd5f53b1f9



附: 网页

<HTML>

<HEAD>

<TITLE>New Page</TITLE>

</HEAD>

<BODY>


<OBJECT ID="MyOCX1" WIDTH=1072 HEIGHT=875

 CLASSID="CLSID:703D14C2-14BC-429E-876E-97350A142162">

    <PARAM NAME="_Version" VALUE="65536">

    <PARAM NAME="_ExtentX" VALUE="28358">

    <PARAM NAME="_ExtentY" VALUE="23119">

    <PARAM NAME="_StockProps" VALUE="0">

</OBJECT>


</BODY>

</HTML>


///////////////////////////// 可使OCX在IE中显示无边框 

<BODY leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0">


==================================================

Web网页中内嵌Activex的Activex插件开发

http://www.cnblogs.com/lidabo/p/3483134.html

浏览器插件之ActiveX开发(一)(二).....(五)
http://www.cnblogs.com/qguohog/archive/2013/01/22/2871805.html


OCX开发,尽量不要用IE作为浏览器(这个结论错了)

http://blog.csdn.net/arwen/article/details/2227858



IE的OCX实现全屏:

可在 OnMButtonUp 中加入SwitchFullScreen();


全屏的实现:


定义:

VARIANT_BOOL SwitchFullScreen(void);

VARIANT_BOOL m_FullScreen;

CWnd* m_ParentWnd;


实现:

VARIANT_BOOL C::SwitchFullScreen(void)
{
	CWnd* parentWnd=this->GetParent();
	if (m_ParentWnd==NULL && parentWnd!=this->GetDesktopWindow())
	{
		m_ParentWnd=parentWnd;
	}

	if (this->m_FullScreen)
	{
		this->ShowWindow(SW_RESTORE);
		::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);
		CRect parentBounds;
		m_ParentWnd->GetClientRect(parentBounds);

		this->SetParent(m_ParentWnd);
		this->MoveWindow(parentBounds);
	}
	else
	{
		this->SetParent(NULL);
		::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);
		this->ShowWindow(SW_MAXIMIZE);
	}
	if (this->m_FullScreen)
	{
		this->m_FullScreen=VARIANT_FALSE;
	}
	else
	{
		this->m_FullScreen=VARIANT_TRUE;
	}
	
	return this->m_FullScreen;
}

CKeeOcxCtrl::SwitchFullScreen(void){CWnd* parentWnd=this->GetParent();if (m_ParentWnd==NULL && parentWnd!=this->GetDesktopWindow()){m_ParentWnd=parentWnd;}if (this->m_FullScreen){this->ShowWindow(SW_RESTORE);::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);CRect parentBounds;m_ParentWnd->GetClientRect(parentBounds);this->SetParent(m_ParentWnd);this->MoveWindow(parentBounds);}else{this->SetParent(NULL);::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);this->ShowWindow(SW_MAXIMIZE);}if (this->m_FullScreen){this->m_FullScreen=VARIANT_FALSE;}else{this->m_FullScreen=VARIANT_TRUE;}return this->m_FullScreen;}

CKeeOcxCtrl::SwitchFullScreen(void){CWnd* parentWnd=this->GetParent();if (m_ParentWnd==NULL && parentWnd!=this->GetDesktopWindow()){m_ParentWnd=parentWnd;}if (this->m_FullScreen){this->ShowWindow(SW_RESTORE);::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);CRect parentBounds;m_ParentWnd->GetClientRect(parentBounds);this->SetParent(m_ParentWnd);this->MoveWindow(parentBounds);}else{this->SetParent(NULL);::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);this->ShowWindow(SW_MAXIMIZE);}if (this->m_FullScreen){this->m_FullScreen=VARIANT_FALSE;}else{this->m_FullScreen=VARIANT_TRUE;}return this->m_FullScreen;}

CKeeOcxCtrl::SwitchFullScreen(void){CWnd* parentWnd=this->GetParent();if (m_ParentWnd==NULL && parentWnd!=this->GetDesktopWindow()){m_ParentWnd=parentWnd;}if (this->m_FullScreen){this->ShowWindow(SW_RESTORE);::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);CRect parentBounds;m_ParentWnd->GetClientRect(parentBounds);this->SetParent(m_ParentWnd);this->MoveWindow(parentBounds);}else{this->SetParent(NULL);::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);this->ShowWindow(SW_MAXIMIZE);}if (this->m_FullScreen){this->m_FullScreen=VARIANT_FALSE;}else{this->m_FullScreen=VARIANT_TRUE;}return this->m_FullScreen;}

VARIANT_BOOL CShowMain::SwitchFullScreen(void)
{
	CWnd* parentWnd=this->GetParent();
	if (m_ParentWnd==NULL && parentWnd!=this->GetDesktopWindow())
	{
		m_ParentWnd=parentWnd;
	}

	if (this->m_FullScreen)
	{
		this->ShowWindow(SW_RESTORE);
		::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);
		CRect parentBounds;
		m_ParentWnd->GetClientRect(parentBounds);

		this->SetParent(m_ParentWnd);
		this->MoveWindow(parentBounds);
	}
	else
	{
		this->SetParent(NULL);
		::SetWindowPos(this->GetSafeHwnd(), HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);
		this->ShowWindow(SW_MAXIMIZE);
	}
	if (this->m_FullScreen)
	{
		this->m_FullScreen=VARIANT_FALSE;
	}
	else
	{
		this->m_FullScreen=VARIANT_TRUE;
	}
	
	return this->m_FullScreen;
}

你可能感兴趣的:(编写IE的ActiveX控件 (基础篇))