在使用 WndProc 钩子(Hook)从 Win32 API 获取消息后,我试图获取鼠标线..
下面是我的代码..它不长,应该很容易理解.. 我边走边学这一切,只是不知道如何将 lParam 更改为点 x 和 y..
任何帮助都会很好,谢谢 :)
private const int WM_LEFTBUTTONDOWN = 0x0201;
private const int WM_LEFTBUTTONUP = 0x0202;
private const int WM_MOUSEMOVE = 0x0200;
private const int WM_MOUSEWHEEL = 0x020A;
private const int WM_RIGHTBUTTONDOWN = 0x0204;
private const int WM_RIGHTBUTTONUP = 0x0205;
public MainWindow()
{
InitializeComponent();
}
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
HwndSource source = PresentationSource.FromVisual(this) as HwndSource;
source.AddHook(WndProc);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_MOUSEMOVE)
{
label1.Content = "Msg: " + msg + " wParam: " + wParam + " lParam: " + lParam;
}
return IntPtr.Zero;
}
最佳答案
您可以使用 Point(int dw)
构造函数:
Point point = new Point(lParam.ToInt32());
...
来自关于 int dw
参数的 MSDN:
The low-order 16 bits of the dw parameter specify the horizontal x-coordinate and the higher 16 bits specify the vertical y-coordinate for the new Point.
关于c# - WndProc 将 lParam 挂接到 xy 线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9748754/