博主首页

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);

 

posted @ 2023-07-14 14:14  笑~笑  阅读(313)  评论(0编辑  收藏  举报