Java / SWT:如何从嵌入式窗口接收鼠标事件 [英] Java/SWT: How to receive mouse events from an embedded window

查看:189
本文介绍了Java / SWT:如何从嵌入式窗口接收鼠标事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用'reparenting'将Windows应用程序嵌入到我的SWT应用程序中。那部分工作正常。我现在想将我的SWT应用程序挂钩到嵌入式应用程序的消息队列中以接收鼠标移动事件。

I am embedding a windows application into my SWT application using 'reparenting'. That part works ok. I would now like to hook my SWT app into the message queue for the embedded app to receive mouse move events.

我看到SWT中的操作系统类有多少添加钩子的有趣方法,但我还没弄清楚如何使用它们。

I see that the OS class in SWT has a number of interesting methods for adding hooks but I have not been able to figure out how to use them.

任何人都可以帮忙吗?

谢谢

推荐答案

这应该可行,但它依赖于使用反射来调用非API,所以在你的自己承担风险。

This should work, but it relies on using reflection to call non-API, so use it at your own risk.

使用反射可以访问Display.addControl()和Display.removeControl()。然后,使用它将Windows应用程序的HWND和拥有控件添加到Display对象。现在,当鼠标移动事件被发送到嵌入式应用程序时,相应的控件应该获得鼠标移动事件。

Use reflection to make Display.addControl() and Display.removeControl() accessible. Then, use it to add the HWND of the Windows application and the owning control to the Display object. Now, when a mouse move event is sent to the embedded app, the corresponding Control should get a mouse move event.

为了更好的衡量,您应该在拥有时添加DisposeListener控制并调用removeControl(),这样事件就不会被发送到死HWND。

For good measure you should add a DisposeListener on the owning Control and call removeControl() so events won't get sent to the dead HWND.

这篇关于Java / SWT:如何从嵌入式窗口接收鼠标事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆