java – 使用JNA获取GetForegroundWindow();
发布时间:2020-12-14 05:37:51 所属栏目:Java 来源:网络整理
导读:我曾经问过一个类似的问题( https://stackoverflow.com/questions/5206633/java-find-out-what-application-window-is-in-focus),但是我被引导使用JNI,而且我没有太多的成功…我已经阅读了一些教程,而一些工作正常,其他人还没有无法获取我需要的信息,这是前
我曾经问过一个类似的问题(
https://stackoverflow.com/questions/5206633/java-find-out-what-application-window-is-in-focus),但是我被引导使用JNI,而且我没有太多的成功…我已经阅读了一些教程,而一些工作正常,其他人还没有无法获取我需要的信息,这是前台窗口的标题.
现在我正在研究JNA,但是我不知道如何访问GetForegroundWindow()…我想我可以打印文本,一旦我得到窗口的句柄使用这个代码(在另一个线程上找到): import com.sun.jna.*; import com.sun.jna.win32.*; public class jnatest { public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32",User32.class); int GetWindowTextA(PointerType hWnd,byte[] lpString,int nMaxCount); } public static void main(){ byte[] windowText = new byte[512]; PointerType hwnd = //GetForegroundWindow() (?)... User32.INSTANCE.GetWindowTextA(hwnd,windowText,512); System.out.println(Native.toString(windowText)); } } 有什么建议么?谢谢! 解决方法
如何简单地添加一个方法调用来匹配本地的GetForegroundWindow到你的界面,像这样:
import com.sun.jna.*; import com.sun.jna.platform.win32.WinDef.HWND; import com.sun.jna.win32.*; public class JnaTest { public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32",User32.class); HWND GetForegroundWindow(); // add this int GetWindowTextA(PointerType hWnd,int nMaxCount); } public static void main(String[] args) throws InterruptedException { byte[] windowText = new byte[512]; PointerType hwnd = User32.INSTANCE.GetForegroundWindow(); // then you can call it! User32.INSTANCE.GetWindowTextA(hwnd,512); System.out.println(Native.toString(windowText)); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- java – 在Drools 6.5.0和Drools 7.0.0中序列化后,Temporal
- JAXB注释 – 映射接口和@XmlElementWrapper
- eclipse 中文件引用报错不能编译,但引用文件确实存在
- 差异b / w超线程和多线程?
- Java基础教程之继承详解
- Java几种常见的排序算法
- 详解Intellij IDEA 2017 debug断点调试技巧(总结)
- Java Swing中的JButton、JComboBox、JList和JColorChooser组
- java – Retrofit 2.0抛出“IllegalArgumentException:@Fi
- java使用poi读取excel文件代码示例