c# - 重写 .NET WebBrowsers WndProc

标签 c# .net winforms webbrowser-control wndproc

对于我的一个项目,我覆盖了一个 AXShockwaveFlash 控件以禁用右键单击,我可以使用以下代码对其进行管理;

public class FlashPlayer : AxShockwaveFlashObjects.AxShockwaveFlash
{
    private const int WM_MOUSEMOVE = 0x0200;
    private const int WM_MOUSEWHEEL = 0x020A;
    private const int WM_LBUTTONDOWN = 0x0201;
    private const int WM_LBUTTONUP = 0x0202;
    private const int WM_LBUTTONDBLCLK = 0x0203; 
    private const int WM_RBUTTONDOWN = 0x0204;
    private const int WM_RBUTTONUP = 0x0205;                      

    public new event MouseEventHandler DoubleClick;

    public new event MouseEventHandler MouseDown;

    public new event MouseEventHandler MouseUp;

    public new event MouseEventHandler MouseMove;

    public FlashPlayer()
    {
        this.HandleCreated += FlashPlayer_HandleCreated; // listen for the HandleCreated event.
    }

    void FlashPlayer_HandleCreated(object sender, EventArgs e) // make required configuration changes.
    {
        this.AllowFullScreen = "true";
        this.AllowNetworking = "all";
        this.AllowScriptAccess = "always";
    }

    protected override void WndProc(ref Message m) // Override's the WndProc and disables Flash activex's default right-click menu and if one exists shows the attached ContextMenuStrip.
    {
        switch (m.Msg)
        {
            case WM_LBUTTONDOWN:
                if (this.MouseDown != null) this.MouseDown(this, new MouseEventArgs(MouseButtons.Left, 1, Cursor.Position.X, Cursor.Position.Y, 0));
                break;
            case WM_LBUTTONUP:
                if (this.MouseUp != null) this.MouseUp(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
                break;
            case WM_MOUSEMOVE:
                if (this.MouseMove != null) this.MouseMove(this, new MouseEventArgs(MouseButtons.None, 0, Cursor.Position.X, Cursor.Position.Y, 0));
                break;
            case WM_RBUTTONDOWN:
                if (this.ContextMenuStrip != null) this.ContextMenuStrip.Show(Cursor.Position.X, Cursor.Position.Y);
                m.Result = IntPtr.Zero; // don't allow actual flash control process the message by flagging it as processed.
                return;
            case WM_LBUTTONDBLCLK:
                if (this.DoubleClick != null) this.DoubleClick(this, new MouseEventArgs(MouseButtons.Left, 2, Cursor.Position.X, Cursor.Position.Y, 0));
                m.Result = IntPtr.Zero; // don't allow actual flash control process the message by flagging it as processed.
                return;
        }

        base.WndProc(ref m); // when we're done with processing the events, let the message pass to others also too.
    }
}

我正在尝试将代码也用于 WebBrowser 控件,但我在 WebBrowser 的 WndProc 上的点击事件根本没有被捕获。

有什么想法吗?

更新:我想做的是完全禁用网络浏览器上的右键单击,IsWebBrowserContextMenuEnabled 在我的情况下不起作用,因为 flash 组件在网络浏览器中仍然处理右键单击并呈现它自己的菜单。

最佳答案

根据您的更新,我猜问题是 WebBrowser 没有收到消息,因为消息被重定向到 Flash 窗口。使 Flash Player 无窗口(我认为这是一个 wmode 参数)可能会起作用,否则您需要枚举 Web 浏览器的子窗口以找到该控件,然后将其子类化。

关于c# - 重写 .NET WebBrowsers WndProc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4934789/

相关文章:

c# - .NET 中 ref 和 out 参数的区别

.net - VS : Events cannot be set on the object passed to the event binding service 中的设计器问题

c# - 如何为 C# Windows 应用程序创建自动更新

c# - 使用 C# 更改 XML 文件中的节点名称

c# - 如何在 C# 中不使用 DataTable.Select() 对数据表进行排序?

c# - 在两个不同的代码块使用相同的锁对象?

c# - XDocument.Save() 在每个 XElement 上添加不需要的命名空间

c# - 锁定关键字和应用程序重置

C#:如何将特殊字符写入 ADLDS?

c# - Winforms Bindingsource Datamember 属性界面什么都不显示