c# - WndProc 将 lParam 挂接到 xy 线?

标签 c# wpf winapi

在使用 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/

相关文章:

wpf - 为什么 ICollectionView<T> 没有 .Net 接口(interface)?

perl - Perl 中的 NTLM 授权

c++ - Windows 上 MapViewOfFile 的引用计数问题

c# - 如何在 C# 中创建返回类的新实例的 setter? (用于使对象不可变)

c# - Android 上的 Xamarin Profiler 错误(运行时太旧)

C# 属性路径

c# - C# 应用程序中的管理员权限提示弹出窗口

c - 为什么我的键盘记录器不起作用?

c# - 如何在 Xamarin 表单 slider 控件中显示刻度线

c# - Linq 表达式属性类型