我在尝试让这个 JNA findwindow 工作时遇到问题,它给我 Windows ID (HWND) 而不是一些疯狂的输出 (native@0xc41bcc)。
我通过使用 C# 了解到,在使用 findwindow 时,它会提供找到的窗口的 ID,然后我可以使用该 ID 来移动/调整该窗口的大小/等等。
我的代码:
public String exec(ITestExecutionServices tes, String[] args) {
try {
writer = new PrintWriter("c:/temp/the-file-name.txt", "UTF-8");
} catch (FileNotFoundException | UnsupportedEncodingException e1) {
e1.printStackTrace();
}
try {
final User32 user32 = User32.INSTANCE;
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
user32.EnumWindows(new WNDENUMPROC() {
@Override
public boolean callback(HWND hWnd, Pointer arg1) {
byte[] windowText = new byte[512];
user32.GetWindowTextA(hWnd, windowText, 512);
String wText = Native.toString(windowText);
wText = (wText.isEmpty()) ? "" : wText;
if (wText.toLowerCase().contains("- funct test -")) {
writer.println("text: " + wText);
writer.println("HWND: " + hWnd);
//User32.INSTANCE.SetWindowPos(hwnd, new HWND(Pointer.createConstant(HWND_BOTTOM)), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
WinDef.HWND hwndFound = User32.INSTANCE.FindWindow(null, wText);
writer.println("hwndFound: " + hwndFound);
writer.println("t/f: " + User32.INSTANCE.MoveWindow(hwndFound, 500, 500, 10, 100, true));
//User32.INSTANCE.SetWindowPos(hWnd, new HWND(Pointer.createConstant(HWND_BOTTOM)), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
return true;
}
}, null);
}
慕尼黑8549860
相关分类