How can I read the window title with JNI or JNA?(如何使用 JNI 或 JNA 读取窗口标题?)
问题描述
希望重返开发领域;主要是使用 Java 调用一些原生的 win32 函数(我不想在 .NET 中构建)....
Looking to get back into the development space; primarily using Java to call some native win32 functions (I don't desire to build in .NET)....
谁能指出我可以使用 Java (JNI/JNA/SWIG) 从不同的运行窗口中读取标题的地方.假设您知道您尝试挂接的应用程序在内存空间的哪个位置.
Can someone point me to a place where I can read the title from a differnt running window using Java (JNI/JNA/SWIG). Assume you would know where in the memory space the application you are attempting to hook into is.
推荐答案
在 JNA 中:
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
int GetWindowTextA(PointerType hWnd, byte[] lpString, int nMaxCount);
}
使用它:
byte[] windowText = new byte[512];
PointerType hwnd = ... // assign the window handle here.
User32.INSTANCE.GetWindowTextA(hwnd, windowText, 512);
System.out.println(Native.toString(windowText));
您可能希望为 HWND 使用正确的结构映射并允许 unicode 支持;您可以在 JNA 网站上找到该信息和更多示例.
You'll probably want to use the proper structure mappings for HWND and also allow unicode support; you can find that information and more examples on how to do that at the JNA website.
GetWindowText 函数的文档位于 MSDN.
The documentation for GetWindowText function is available here in MSDN.
jna.dev.java.net
这篇关于如何使用 JNI 或 JNA 读取窗口标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何使用 JNI 或 JNA 读取窗口标题?


基础教程推荐
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 从 python 访问 JVM 2022-01-01