跟踪多个 WindowsFormsHost 控件中的 WPF 鼠标移动
我有一个 WPF 应用程序,其中有多个 WindowsFormsHost 控件。当应用程序在全屏模式下最大化时,我试图跟踪鼠标在应用程序内的位置。如果用户将鼠标放在顶部屏幕附近,我想显示一个带有附加菜单的窗口。
我可以使用:
- Window.PreviewMouseMove
- InputManager.PreProcessInput,甚至
- HwndSource.FromHwnd(WindowInteropHelper(mainWindow).Handle).AddHook(...)
来接收移动事件,只要鼠标不在 WindowsFormsHost 上移动(如果用户执行此操作,我没有收到事件)。我认为根本问题是因为 WPF 对每个 WindowsFormsHost 使用单独的 HWND。
有没有一种好方法可以跟踪应用程序中的鼠标移动,而无需手动查找每个 WindowsFormsHost 并订阅其鼠标移动事件?如果可能的话,我还想避免使用全局 Windows 鼠标侦听器。
I have a WPF application that has several WindowsFormsHost controls. I'm trying to track the mouse position inside of my application when it is maximized in full-screen mode. If the user puts the mouse near the top screen, I'd like to display a Window with additional menus.
I can use:
- Window.PreviewMouseMove
- InputManager.PreProcessInput, or even
- HwndSource.FromHwnd(WindowInteropHelper(mainWindow).Handle).AddHook(...)
to receive move events so long as the mouse doesn't move over a WindowsFormsHost (if the user does this, I do not receive an event). I think the root problem is because WPF uses a separate HWND for each WindowsFormsHost.
Is there a good way to track the mouse movements across my application without having to manually find each WindowsFormsHost and subscribe to its mouse move events? I'd also like to avoid a global Windows mouse listener if possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为除了使用概述 此处以及诸如 Visual.PointFromScreen 将全局屏幕坐标转换为应用程序本地坐标。
I don't think there is a good solution besides using a global mouse hook as outlined here along with a function like Visual.PointFromScreen to translate the global screen coordinate to an application local coordinate.