`
Eric_2007
  • 浏览: 24469 次
  • 性别: Icon_minigender_1
  • 来自: 辽宁
社区版块
存档分类
最新评论

How to get IOleSite interface of the WebBrowser in

阅读更多
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());

              }

 

         }

     }

 
分享到:
评论

相关推荐

    Using the WebBrowser Control in ASP.NET

    Using the WebBrowser Control in ASP.NET

    This example uses the WebBrowser control to load a web page

    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_for_.NET_2018.2.53.0

    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 ...

    Eo Webbrowser 解决win10 Failed to resolve LoadLibrary

    初始化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...

    C# 使用chromium内核浏览器源码

    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.

    eric5-5.3.1

    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...

    Retrieve HttpOnly Session Cookie in WebBrowser

    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...

    VB编程资源大全(英文源码 控件)

    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>...

    VB编程资源大全(英文源码 网络)

    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...

    WebBrowser控件使用详解

    WebBrowser控件使用详解,WebBrowser控件使用详解

    C#基于WebBrowser获取cookie的实现方法

    主要介绍了C#基于WebBrowser获取cookie的实现方法,实例分析了C#基于WebBrowser简单读取浏览谷歌网站cookie的相关技巧,非常简单实用,需要的朋友可以参考下

    vb6_Webbrowser控件使用技巧

    vb6_Webbrowser控件使用技巧 1、获得浏览器信息: Private Sub Command1_Click() WebBrowser1.Navigate "http://www.applevb.com" End Sub Private Sub Command2_Click() Dim oWindow Dim oNav Set oWindow ...

    C#中WebBrowser控件的简单调用

    1,在项目中引用程序集拓展中的Microsoft.mshtml后,可以在公共控件中找到WebBrowser控件。 2,在窗体中加入三个按钮,然后添加WebBrowser控件,右键控件选属性,设置相应的属性。 3,设置WebBrowser控件的属性 ...

    WebBrowser执行JS脚本示例

    涵盖了几种常用的 webBrowser执行javascript的方法, execScript方式: NavigateScript方式: 其中需要作如下设置 由于visual studio2005 中WebBrowser控件已经实现了IDocHostUIHandler,所以 只要把应用程序属性类的...

    UE4解决WebBrowser无法播放H.264替换文件

    UE4解决WebBrowser无法播放H.264的问题 4.25、4.26、4.27实测没问题,其他版本待测试 编译好的CEF3源码,带替换路径说明,直接替换即可

    WebBrowser控件技巧集

    WebBrowser控件技巧集

    WebBrowser Demo

    WebBrowser Demo WebBrowser DemoWebBrowser

    WebBrowser

    WebBrowser.exe 损坏文件,此文件为修复工具。

    EO.WebBrowser帮助文档,一款谷歌内核的WebBrowser

    c# 桌面应用 WebBrowser 是IE浏览器内核,目前很多网站不支持了,从国外网站找到一个 谷歌内核的WebBrowser 名字叫 EO.WebBrowser ,比较好用,本文档是他的帮助文档。

    webbrowser滚动条隐藏

    webbrowser滚动条隐藏

Global site tag (gtag.js) - Google Analytics