How can I read the window title with JNI or JNA?

Want to return to the development space; First of all, using Java to call some native win32 functions (I do not want to create .NET) ....

Can someone tell me a place where I can read the title from another executable window using Java (JNI / JNA / SWIG). Suppose you know where in the memory space the application you are trying to connect to is.

+6
java winapi swig jni jna
source share
1 answer

In JNA:

public interface User32 extends StdCallLibrary { User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class); int GetWindowTextA(PointerType hWnd, byte[] lpString, int nMaxCount); } 

To use it:

 byte[] windowText = new byte[512]; PointerType hwnd = ... // assign the window handle here. User32.INSTANCE.GetWindowTextA(hwnd, windowText, 512); System.out.println(Native.toString(windowText)); 

You might want to use the correct structure mappings for HWND, as well as enable Unicode support; You can find this information and other examples on how to do this on the MSDN website.

Documentation for JNA is available at jna.dev.java.net

+9
source share

All Articles