UMPLatForm.NET 中MiNiWeb浏览器核心技术详解二(接上篇)
2012-08-10 10:48
302 查看
UMPLatForm.NET [/b]中[/b]MiNiWeb[/b]浏览器核心技术详解二[/b]
接上一篇:UMPLatForm.NET 中MiNiWeb浏览器核心技术详解一
3、创建webbrowser扩展组件
从上一节中,我们可以发现上述的所有内容都基本可以归结为两件事:
1. 实现一个iwebbrowser2类型的对象,从中获得application属性
2. 实现dwebbrowserevents2接口来触发事件
实现iwebbrowser2接口
webbrowser控件有两个尚未公开的接口:attachinterfaces()和detachinterfaces()。这些方法用于获得iwebbrowser2接口的引用。
下一步,我们可以添加application属性。
这个属性可以用来创建一个新窗口,并且当创建新窗口事件触发时将浏览器重定向到这个新窗口。
作者: Edward
出处: http://umplatform.blog.51cto.com/
微博: 腾讯
Email: umplatform@126.com或 406590790@qq.com
QQ 交流:406590790 (请注明:平台交流)
QQ群交流:16653241 或 237326100
关于作者:高级工程师、信息系统项目管理师、数据库系统工程师。专注于微软平台项目架构、管理和企业解决方案,多年项目开发与管理经验,曾多次组织并开发多个大型项目,精通DotNet(C#、Asp.NET、ADO.NET、Web Service、WCF),DB原理与技术、SqlServer、Oracle等。熟悉Java、Delhpi及Linux操作系统,有扎实的网络知识。自认在面向对象、面向服务以及数据库领域有一定的造诣。现主要从事DB管理、DB开发、WinForm、WCF、WebService、网页数据抓取以及ASP.NET等项目管理、开发、架构等工作。如有问题或建议,请多多赐教!
本文版权归作者和51CTO博客共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过邮箱或QQ 联系我,非常感谢。
本文出自 “统一项目集成平台” 博客,请务必保留此出处http://umplatform.blog.51cto.com/5232570/960058
接上一篇:UMPLatForm.NET 中MiNiWeb浏览器核心技术详解一
3、创建webbrowser扩展组件
从上一节中,我们可以发现上述的所有内容都基本可以归结为两件事:
1. 实现一个iwebbrowser2类型的对象,从中获得application属性
2. 实现dwebbrowserevents2接口来触发事件
实现iwebbrowser2接口
using System; using System.Security; using System.Runtime.InteropServices; using System.Windows.Forms; using System.Security.Permissions; namespace MiniBrowser { /// <summary> /// An extended version of the <see cref="WebBrowser"/> control. /// </summary> class ExtendedWebBrowser : System.Windows.Forms.WebBrowser { private UnsafeNativeMethods.IWebBrowser2 axIWebBrowser2; /// <summary> /// This method supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// Called by the control when the underlying ActiveX control is created. /// </summary> /// <param name="nativeActiveXObject"></param> [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")] protected override void AttachInterfaces(objectnativeActiveXObject) { this.axIWebBrowser2 = (UnsafeNativeMethods.IWebBrowser2)nativeActiveXObject; base.AttachInterfaces(nativeActiveXObject); } /// <summary> /// This method supports the .NET Framework infrastructure and is not intended to be used directly from your code. /// Called by the control when the underlying ActiveX control is discarded. /// </summary> [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")] protected override void DetachInterfaces() { this.axIWebBrowser2 = null; base.DetachInterfaces(); } /// <summary> /// Returns the automation object for the web browser /// </summary> public object Application { get { return axIWebBrowser2.Application; } } System.Windows.Forms.AxHost.ConnectionPointCookie cookie; WebBrowserExtendedEvents events; /// <summary> /// This method will be called to give you a chance to create your own event sink /// </summary> [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")] protected override void CreateSink() { // Make sure to call the base class or the normal events won't fire base.CreateSink(); events = new WebBrowserExtendedEvents(this); cookie = newAxHost.ConnectionPointCookie(this.ActiveXInstance, events,typeof(UnsafeNativeMethods.DWebBrowserEvents2)); } /// <summary> /// Detaches the event sink /// </summary> [PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")] protected override void DetachSink() { if (null != cookie) { cookie.Disconnect(); cookie = null; } } /// <summary> /// Fires when downloading of a document begins /// </summary> public event EventHandler Downloading; /// <summary> /// Raises the <see cref="Downloading"/> event /// </summary> /// <param name="e">Empty <see cref="EventArgs"/></param> /// <remarks> /// You could start an animation or a notification that downloading is starting /// </remarks> protected void OnDownloading(EventArgs e) { if (Downloading != null) Downloading(this, e); } /// <summary> /// Fires when downloading is completed /// </summary> /// <remarks> /// Here you could start monitoring for script errors. /// </remarks> public event EventHandler DownloadComplete; /// <summary> /// Raises the <see cref="DownloadComplete"/> event /// </summary> /// <param name="e">Empty <see cref="EventArgs"/></param> protected virtual void OnDownloadComplete(EventArgs e) { if (DownloadComplete != null) DownloadComplete(this, e); } …… } }
webbrowser控件有两个尚未公开的接口:attachinterfaces()和detachinterfaces()。这些方法用于获得iwebbrowser2接口的引用。
下一步,我们可以添加application属性。
/// <summary> /// Returns the automation object for the web browser /// </summary> public object Application { get { return axIWebBrowser2.Application; } }
这个属性可以用来创建一个新窗口,并且当创建新窗口事件触发时将浏览器重定向到这个新窗口。
作者: Edward
出处: http://umplatform.blog.51cto.com/
微博: 腾讯
Email: umplatform@126.com或 406590790@qq.com
QQ 交流:406590790 (请注明:平台交流)
QQ群交流:16653241 或 237326100
关于作者:高级工程师、信息系统项目管理师、数据库系统工程师。专注于微软平台项目架构、管理和企业解决方案,多年项目开发与管理经验,曾多次组织并开发多个大型项目,精通DotNet(C#、Asp.NET、ADO.NET、Web Service、WCF),DB原理与技术、SqlServer、Oracle等。熟悉Java、Delhpi及Linux操作系统,有扎实的网络知识。自认在面向对象、面向服务以及数据库领域有一定的造诣。现主要从事DB管理、DB开发、WinForm、WCF、WebService、网页数据抓取以及ASP.NET等项目管理、开发、架构等工作。如有问题或建议,请多多赐教!
本文版权归作者和51CTO博客共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,如有问题,可以通过邮箱或QQ 联系我,非常感谢。
本文出自 “统一项目集成平台” 博客,请务必保留此出处http://umplatform.blog.51cto.com/5232570/960058
相关文章推荐
- UMPLatForm.NET 中MiNiWeb浏览器核心技术详解三(接上篇)
- UMPLatForm.NET 中MiNiWeb浏览器核心技术详解一
- MiNiWeb浏览器核心技术详解
- MiNiWeb浏览器核心技术详解
- MiNiWeb浏览器核心技术详解
- ASP.NET 2.0程序开发详解 ---------15.2 AJAX的核心技术
- 《ASP.NET 2.0网站开发技术详解》China-Pub朋友的评论
- 精通_NET核心技术-高级特性(一)
- 统一项目管理平台(UMPlatForm.NET)-4.7 组织机构管理模块
- .NET Ajax的无刷新技术实例详解(重点)
- 统一项目管理平台(UMPlatForm.NET) 4.8 模块(菜单)管理
- 看《C#和,NET核心技术》的感受
- .NET架构的核心开发技术
- ffmpeg开发之旅(8):Android UVC Camera(USB摄像头)开发核心技术详解
- 技术实操|Apache Spark 内存管理详解(上篇)
- 写一个简易浏览器、ASP.NET核心知识(3)
- 这就是搜索引擎:核心技术详解
- 【缓存技术原理】浏览器端缓存机制详解
- 【缓存技术原理】浏览器端缓存机制详解
- HubbleDotNet开源全文搜索数据库项目--技术详解