我正在尝试在 WPF 应用程序中托管 DirectX 内容。我从这个链接中学到的是继承 HwndHost 并创建自己的 WndProc 实现以及 BuildWindowCore 和 DestroyWindowCore。 https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/walkthrough-hosting-a-win32-control-in-wpf#implement-a-class-to-host-the-microsoft- win32控制
然后我在这里找到了非常有用的实现: https ://github.com/Smartrak/WpfSharpDxControl/blob/master/WpfSharpDxControl/Win32HwndControl.cs
现在,我需要实现另外两个方法,例如 WM_MOUSEMOVE (0x0200) 和 WM_MOUSEWHEEL (0x020A)。我不确定如何正确传递信息,例如鼠标滚轮增量和时间戳。朝这个方向的任何指示都会非常有帮助。
protected override IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch (msg)
{
case NativeMethods.WM_MOUSEMOVE:
//What should go here
break;
case NativeMethods.WM_MOUSEWHEEL:
//What should go here
break;
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;
}
return base.WndProc(hwnd, msg, wParam, lParam, ref handled);
}
谢谢,杰