为什么我实现的IDocHostUIHandler被忽略 [英] Why my implementation of IDocHostUIHandler is ignored

查看:235
本文介绍了为什么我实现的IDocHostUIHandler被忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造派生控件从 web浏览器控制具有自主的IDocHostUIHandler 实施以下的想法从<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.createwebbrowsersitebase%28v=vs.100%29.aspx"相对=nofollow> CreateWebBrowserSiteBase 方式:

I have created derived control from WebBrowser control that has own IDocHostUIHandler implementation following idea from CreateWebBrowserSiteBase method:

该WebBrowser.WebBrowserSite类提供默认实现   在OLE的IDocHostUIHandler接口。您可以提供自己的   这个接口的实现或实施其他任何web浏览器   以自定义的行为的ActiveX控制接口   控制。

The WebBrowser.WebBrowserSite class provides default implementations of the OLE IDocHostUIHandler interface. You can provide your own implementation of this interface or implement any other WebBrowser ActiveX control interface in order to customize the behavior of the control.

这是不工作的问题。我的code相接下来方式:

The problem that is not working. My code looks next way:

[PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
public MyBrowser(){}

protected override WebBrowserSiteBase CreateWebBrowserSiteBase()
{
    var manager = new NewWebBrowserSite(this);
    return manager;
}

protected class NewWebBrowserSite : WebBrowserSite, 
    UnsafeNativeMethods.IDocHostUIHandler
{
    private MyBrowser host;
    public NewWebBrowserSite(MyBrowser h)
        : base(h)
    {
        this.host = h; 
    }

    int UnsafeNativeMethods.IDocHostUIHandler.ShowContextMenu(int dwID, NativeMethods.POINT pt, object pcmdtReserved, object pdispReserved)
    {
        MyBrowser wb = (MyBrowser)this.host;
        // other code
    }

    // rest of IDocHostUIHandler methods
}

我的问题是:

My questions are:

  1. 请我一定要实现其他接口,使之工作;
  2. 是由设计,我看过一些<一href="http://social.msdn.microsoft.com/forums/en-US/winforms/thread/79c1f5a7-372e-4777-84e5-862d3f14267f/"相对=nofollow>发布,这是关系到.NET框架的实施 web浏览器
  3. 的错误
  1. Do I have to implement other interfaces to make it working;
  2. Is that by design, I have read some post that it is related to a bug in .net framework implementation of WebBrowser

我知道这是有可能去 ICustomDoc.SetUIHandler 的方式,但它不是我所期待的。

I know that is possible to go ICustomDoc.SetUIHandler way, but it is not what I am looking for.

我是有想法在某些时候放弃使用C#,做与非托管code。是的呀?

I was having idea at some point to give up with c# and do that with unmanaged code. Is that the way?

推荐答案

您不能简单地覆盖由一个类实现的接口。如果方法的IDocHostUIHandler没有标记为虚拟的,你不能代替他们。

You can't simply override the interfaces implemented by a class. If the methods for IDocHostUIHandler are not marked as virtual, you can't replace them.

该接口是 UnsafeNativeMethods定义的事实也是,你可能不应该与它搞乱线索,除非你有你一个非常好的主意重新做的事情。

The fact that the interface is defined in UnsafeNativeMethods is also a clue that you probably shouldn't be messing with it unless you have a very good idea of what you're doing.

这篇关于为什么我实现的IDocHostUIHandler被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆