2011-02-08 66 views
2

对于我的其中一个项目,我重写了一个AXShockwaveFlash控件以禁用右键单击,我可以使用以下代码管理它;重写.NET WebBrowsers WndProc

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控件,但在web浏览器的WndProc我的点击事件没有被捕获的。

任何想法?

更新:我想要做的是禁止在网络浏览器完全用鼠标右键单击,IsWebBrowserContextMenuEnabled并不在我的条件下工作,因为在网络浏览器中的闪光成分仍然处理正确的点击和渲染它是自己的菜单。

+2

另一个右键单击禁用..你想实现什么?不要限制用户的权利做他想做的事 – abatishchev 2011-02-08 15:27:32

+1

对不起,我不会在这里讨论UI的决定。基本上这个想法是我自己的右键单击菜单,我可以为播放的电影提供诸如无边界形式,聊天室等功能。 – HuseyinUslu 2011-02-08 15:37:42

回答

2

与您的更新,我想这个问题是,web浏览器不接受,因为消息的消息被重定向到一个Flash窗口。使Flash播放器无窗口(我认为它是一个wmode参数)可能会起作用,否则您需要枚举Web浏览器的子窗口来查找控件,然后对其进行子类化。

0

我发现在这个线程(所以,不要怪我)有点复杂的解决方案: social.msdn.microsoft.com/forums...

+0

我实际上已经实现了这种方法来禁用右键点击我的原生Flash控件,但我提到的Flash控件嵌入在webbbrowser控件中。 – HuseyinUslu 2011-02-15 09:33:39