我编写了这个垃圾:
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
class SmartWebBrowser : WebBrowser
{
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;
private const int WM_RBUTTONDBLCLK = 0x0206;
private const int WM_MBUTTONUP = 0x0208;
private const int WM_MBUTTONDOWN = 0x0209;
public override bool PreProcessMessage(ref Message msg)
{
bool allow_propagation = true;
switch (msg.Msg)
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONUP:
case WM_MBUTTONDOWN:
allow_propagation = false; //breakpoint here
break;
}
if (allow_propagation)
return base.PreProcessMessage(ref msg);
else
return false;
}
protected override void WndProc(ref Message msg)
{
bool allow_propagation = true;
switch (msg.Msg)
{
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
case WM_RBUTTONDBLCLK:
case WM_MBUTTONUP:
case WM_MBUTTONDOWN:
allow_propagation = false; //breakpoint here
break;
}
if (allow_propagation)
base.WndProc(ref msg);
}
}
}
但断点永远不会触发。我做错了什么?覆盖WndProc这样的事情是常见的做法,但这里没有工作。
我试图阻止点击传播到文档,因此用户可以滚动它,但无法通过点击与其进行互动。