我试图让我的应用程序能够聚焦另一个窗口(在这种情况下为记事本)
我的班级看起来像这样
public static class Win32WindowUtils {
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class, W32APIOptions.DEFAULT_OPTIONS);
HWND GetParent(HWND hWnd);
HWND FindWindow(String lpClassName, String lpWindowName);
HWND SetFocus(HWND hWnd);
HWND FindWindowEx(HWND hwndParent, HWND hwndChildAfter, String lpszClass, String lpszWindow);
int GetWindowText(HWND hWnd, char[] lpString, int nMaxCount);
}
private static final int WIN_TITLE_MAX_SIZE = 512;
public static HWND GetWindowHandle(String strSearch, String strClass) {
char[] lpString = new char[WIN_TITLE_MAX_SIZE];
String strTitle;
int iFind = -1;
HWND hWnd = User32.INSTANCE.FindWindow(strClass, null);
while(hWnd …Run Code Online (Sandbox Code Playgroud)