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

查看:187
本文介绍了如何用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的文档位于 jna.dev.java.net

这篇关于如何用JNI或JNA阅读窗口标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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