jna获取windos所有窗口
<dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna</artifactId> <version>5.6.0</version> </dependency> <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna-platform</artifactId> <version>5.6.0</version> </dependency>
public static void showWindow(){ final User32 user32 = User32.INSTANCE; user32.EnumWindows((hWnd, arg1) -> { char[] windowText = new char[1000]; User32.INSTANCE.GetWindowText(hWnd, windowText, 5120); String wText = Native.toString(windowText); boolean b = User32.INSTANCE.IsWindowVisible(hWnd); if (wText.isEmpty()) { return true; } System.out.println(wText); return true; }, null); }
获取窗口宽高、移动窗口
public static void main(String[] args) { WinDef.HWND hwnd = User32.INSTANCE.FindWindow(null,"D:\\360MoveData\\Users\\Administrator\\Desktop\\工作.txt - " + "Notepad++"); WinDef.RECT rect = new WinDef.RECT(); User32.INSTANCE.GetWindowRect(hwnd,rect); User32.INSTANCE.MoveWindow(hwnd,100,100,1200,800,true); int left = rect.left; System.out.println(left); //showWindow(); }
显示还原最小化窗口
User32.INSTANCE.ShowWindow(hwnd,9); User32.INSTANCE.SetForegroundWindow(hwnd);