有什么方法可以从使用 SWING 开发的程序中读取数据。我可以使用 Native JNA 读取窗口的标题。我已经尝试了下面的代码,它给了我窗口的标题。
public class JNATest {
HWND window = null;
public static void main(String[] args) {
JNATest jna = new JNATest();
if(jna.isWindowOpen("Test")){
jna.activateWindow();
}
}
public void activateWindow() {
if(window != null) {
User32.INSTANCE.ShowWindow(window, 9);
User32.INSTANCE.SetForegroundWindow(window);
}
}
public boolean isWindowOpen(String title) {
window = null;
User32.INSTANCE.EnumWindows(new WNDENUMPROC() {
@Override
public boolean callback(HWND hWnd, Pointer arg1) {
if(window == null) {
char[] windowText = new char[512];
User32.INSTANCE.GetWindowText(hWnd, windowText, 512);
String wText = Native.toString(windowText);
if (wText.contains(title)) {
window = hWnd;
}
System.out.println(" - Found sub window / control class: " + new String(windowText).trim());
}
return true;
}
}, null);
return window != null;
}