如何使用 JNI 或 JNA 读取窗口标题? [英] How can I read the window title with JNI or JNA?

查看:70
本文介绍了如何使用 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 读取窗口标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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