C# 鼠标滚轮事件在一台计算机上未触发,在另一台计算机上工作

C# 鼠标滚轮事件在一台计算机上未触发,在另一台计算机上工作,c#,wpf,hwnd,C#,Wpf,Hwnd,问题是: 我编写了一个WPF应用程序,它使用一个Hwnd来承载一个绘图表面。hwnd负责发回发生的鼠标事件。在我的电脑上,一切正常,我看到522(0x020A)鼠标滚轮信息没有问题 我在另一台计算机上安装了同样的软件,但事件没有发生。我甚至将所有事件消息记录到一个文件中,以查看522是否触发,但它从未出现 我尝试过的事情: -确保Hwnd具有焦点。我不仅制作了一个每秒钟都会重新聚焦的线程,我还确保在我的计算机上(正在工作)“IsFocused”对于hwnd是正确的 -关闭正在运行的任何其他程序。

问题是:

我编写了一个WPF应用程序,它使用一个Hwnd来承载一个绘图表面。hwnd负责发回发生的鼠标事件。在我的电脑上,一切正常,我看到522(0x020A)鼠标滚轮信息没有问题

我在另一台计算机上安装了同样的软件,但事件没有发生。我甚至将所有事件消息记录到一个文件中,以查看522是否触发,但它从未出现

我尝试过的事情:

-确保Hwnd具有焦点。我不仅制作了一个每秒钟都会重新聚焦的线程,我还确保在我的计算机上(正在工作)“IsFocused”对于hwnd是正确的

-关闭正在运行的任何其他程序。这包括在后台运行的计算机的正常功能,以防某些东西使焦点偏离

-切换鼠标。我确实用了我在电脑上使用的鼠标,但它在新电脑上仍然不起作用

以下是基本代码:

public abstract class Win32HwndControl : HwndHost
{
    protected IntPtr Hwnd { get; private set; }
    protected bool HwndInitialized { get; private set; }

    private const string WindowClass = "HwndWrapper";

    protected Win32HwndControl()
    {
    }

protected override HandleRef BuildWindowCore(HandleRef hwndParent)
{
    var wndClass = new NativeMethods.WndClassEx();
    wndClass.cbSize = (uint)Marshal.SizeOf(wndClass);
    wndClass.hInstance = NativeMethods.GetModuleHandle(null);
    wndClass.lpfnWndProc = NativeMethods.DefaultWindowProc;
    wndClass.lpszClassName = WindowClass;
    wndClass.hCursor = NativeMethods.LoadCursor(IntPtr.Zero, NativeMethods.IDC_ARROW);
    NativeMethods.RegisterClassEx(ref wndClass);

    Hwnd = NativeMethods.CreateWindowEx(
            0, WindowClass, "", NativeMethods.WS_CHILD | NativeMethods.WS_VISIBLE,
            0, 0, (int)Width, (int)Height, hwndParent.Handle, IntPtr.Zero, IntPtr.Zero, 0);

    return new HandleRef(this, Hwnd);
 }

 protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        switch (msg)
        {
            case NativeMethods.WM_LBUTTONDOWN:
                RaiseMouseEvent(MouseButton.Left, Mouse.MouseDownEvent);
                break;

            case NativeMethods.WM_LBUTTONUP:
                RaiseMouseEvent(MouseButton.Left, Mouse.MouseUpEvent);
                break;

            case NativeMethods.WM_RBUTTONDOWN:
                RaiseMouseEvent(MouseButton.Right, Mouse.MouseDownEvent);
                break;

            case NativeMethods.WM_RBUTTONUP:
                RaiseMouseEvent(MouseButton.Right, Mouse.MouseUpEvent);
                break;
            case NativeMethods.WM_MOUSEWHEEL:
                RaiseMouseWheelEvent(wParam.ToInt32(), Mouse.MouseWheelEvent);
                break;

        }

        return base.WndProc(hwnd, msg, wParam, lParam, ref handled);
    }
这个类有更多的代码,但我已经确认它没有命中WndProc方法


关于为什么这会发生在一台计算机上而不是另一台计算机上,有什么提示吗?

尝试获取最后一个错误:Crystal ball说一台机器启动Win10,另一台机器启动旧版本。鼠标滚轮通知在Win10中已更改,它现在发送到正在悬停的窗口,而不是具有焦点的窗口。我在Windows 10上,另一台计算机是Windows 7。所以这似乎仍然是一个焦点问题?我在不同的Windows 10机器上有相同的问题,但在大多数机器上都有效。