跟踪多个 WindowsFormsHost 控件中的 WPF 鼠标移动

发布于 2024-09-27 11:32:10 字数 509 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢望 2024-10-04 11:32:10

我认为除了使用概述 此处以及诸如 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文