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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章