How to get IOleSite interface of the WebBrowser in an ActiveX control
//From http://www.cnblogs.com/jonnyyu/archive/2004/02/14/1248.html
//based on Q172763 HOWTO: Retrieve the Top-Level IWebBrowser2 Interface from an ActiveX Control
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using System.Security;
using System.Runtime.InteropServices;
using SHDocVw;
//Use strongname to apply the customized pemission set
[assembly : AssemblyKeyFile(@"c:\key.snk")]
//Q814669 PRB: Strong Named User Controls Do Not render in Internet Explorer
[assembly: System.Security.AllowPartiallyTrustedCallers]
namespace Microsoft.Samples.WinForms.Cs.SimpleControl
{
public class SimpleControl : System.Windows.Forms.Control
{
public SimpleControl() :base()
{
Button btn = new Button();
btn.Parent = this;
btn.Text = "Button1";
btn.Location = new Point(10,10);
btn.Click += new EventHandler(Btn_OnClick);
Controls.Add(btn);
}
//from shlguid.h
Guid SID_STopLevelBrowser = new Guid(0x4C96BE40, 0x915C, 0x11CF, 0x99, 0xD3, 0x00, 0xAA, 0x00, 0x4A, 0xE8, 0x37);
Guid SID_SWebBrowserApp = typeof(SHDocVw.IWebBrowserApp).GUID;
private void Btn_OnClick(object sender, EventArgs e)
{
try
{
Guid guidIServiceProvider = typeof(IServiceProvider).GUID;
Guid guidIWebBrowser2 = typeof(SHDocVw.IWebBrowser2).GUID;
object objIServiceProvider2;
object objIWebBrowser2;
Type typeIOleObject = this.GetType().GetInterface("IOleObject",true);
//call the method on that interface
object oleClientSite = typeIOleObject.InvokeMember("GetClientSite",
BindingFlags.Instance|BindingFlags.InvokeMethod|BindingFlags.Public,
null,this,null);
IServiceProvider serviceProvider = oleClientSite as IServiceProvider;
serviceProvider.QueryService(ref SID_STopLevelBrowser,ref guidIServiceProvider, out objIServiceProvider2);
serviceProvider = objIServiceProvider2 as IServiceProvider;
serviceProvider.QueryService(ref SID_SWebBrowserApp, ref guidIWebBrowser2, out objIWebBrowser2);
IWebBrowser2 webBrowser = objIWebBrowser2 as IWebBrowser2;
MessageBox.Show(webBrowser.LocationURL);
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
}
分享到:
相关推荐
在ASP.NET中,WebBrowser控件是一个非常有用的工具,它允许开发者在网页应用程序中嵌入一个内置的浏览器组件。这个控件使得开发人员能够模拟用户的网络浏览行为,加载和交互HTML页面,执行JavaScript,以及进行一些...
EO.WebBrowser is a web browser engine based on Google's Chromium project but with native .NET programming interface --- don't worry, it's not a wrapper around the Chrome browser installed on your ...
This example uses the WebBrowser control to load a web page then enumerate and display all of the links on that page. This example could be easily expanded to be used as a web-spider with a little bit...
初始化Eo Webbrowser报错"Failed to resolve LoadLibrary",需要调用eowp.exe,来进行处理,Both EO.Pdf and EO.WebBrowser dynamically create child processes and run browser engine inside the child process at...
I've been using CefSharp Chromium browser component in my projects for some time and I changed the WebBrowser in the project with CefSharp and this is how this application came to life.
In order to enable the remote debugger start eric5, open the preferences dialog and configure the settings on the debugger pages. The remote login must be possible without any further interaction...
on left and right side of a text box.<END><br>40,Assist.zip A simple application with source code which shows how to save the contents of a rich text box without the help of common dialog box.<END>...
In order to help mitigate the risk of cross-site scripting, a new feature has been introduced in Microsoft Internet Explorer 6 SP1. This feature is a new attribute for cookies which prevents them from...
在Windows应用程序开发中,`WebBrowser`控件是一个非常实用的工具,它允许开发者在应用程序内嵌入一个浏览器引擎,从而展示网页内容。本话题主要围绕如何使用`WebBrowser`控件实现网页的放大和缩小功能进行深入探讨...
AdvancedWebBrowser.zip Advanced web browser..something like IE but less options really nice interface..code is very easy to understand..teaches you the basics of using vb.<END><br>54 , iusage.zip...
在.NET框架中,C#提供了一个内置的控件——`WebBrowser`,它允许开发者在Windows应用程序中嵌入一个浏览器引擎,以便展示网页内容。这个控件基于Internet Explorer的渲染引擎,因此它能够处理HTML、CSS和JavaScript...
### WebBrowser 控件使用详解 #### 一、概述 `WebBrowser` 控件是一个功能强大的组件,用于在 Windows 应用程序中展示 HTML 内容。它可以用来浏览互联网上的网页,也可以用来显示本地的 HTML 文件或者自定义的文档...
在C#编程中,WebBrowser控件是一个强大的工具,它允许开发者在Windows应用程序中嵌入一个Web浏览器,以便用户能够浏览网页。同时,通过WebBrowser控件,开发者还可以与网页进行交互,例如获取cookie信息。本文将深入...
1,在项目中引用程序集拓展中的Microsoft.mshtml后,可以在公共控件中找到WebBrowser控件。 2,在窗体中加入三个按钮,然后添加WebBrowser控件,右键控件选属性,设置相应的属性。 3,设置WebBrowser控件的属性 ...
在Windows编程领域,WebBrowser控件是一个非常实用的组件,它允许开发者在应用程序中嵌入一个基于Internet Explorer渲染引擎的浏览器。这篇博客的配套文件主要探讨了如何在WebBrowser控件中实现JavaScript(JS)与...
### vb6_Webbrowser控件使用技巧 #### 一、获得浏览器信息 在Visual Basic 6.0中,可以通过Webbrowser控件获取浏览器的相关信息。具体实现方式如下: 1. **加载网页**: ```vb Private Sub Command1_Click() ...
在.NET框架中,C#提供了一个内置的控件——`WebBrowser`,它允许开发者在应用程序内部嵌入一个浏览器引擎,从而实现与网页交互的功能。本篇将详细讲解如何利用C#的`WebBrowser`控件来获取网页信息,包括HTML源代码、...
WebBrowser控件是Windows应用程序开发中的一个重要组成部分,它允许开发者在他们的应用中嵌入一个能够浏览网页的组件。这个控件通常基于Internet Explorer的核心,因此它支持HTML、CSS和JavaScript等网页技术。在...
涵盖了几种常用的 webBrowser执行javascript的方法, execScript方式: NavigateScript方式: 其中需要作如下设置 由于visual studio2005 中WebBrowser控件已经实现了IDocHostUIHandler,所以 只要把应用程序属性类的...
VB、VBA关于WebBrowser相关操作大全 WebBrowser控件是VB和VBA中常用的控件之一,它允许开发者在应用程序中嵌入网页浏览功能。下面是VB、VBA关于WebBrowser相关操作的总结,涵盖多方面的知识点。 一、防止新窗口...