Handle external windows using java

前端 未结 4 947
小鲜肉
小鲜肉 2020-12-06 11:35

I need to check if an external window (another java program, but not controlled by the program that I\'m working on) is open using the title, and if it open, then either max

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 11:53

    I've just added a lot of win32 related window functions into JNA. You can see the details here.

    // Find and minimize a window:
    WinDef.HWND hWnd = User32.INSTANCE.FindWindow("className", "windowName");
    User32.INSTANCE.ShowWindow(hWnd, WinUser.SW_MINIMIZE);
    

    You can also enumerate all windows:

    final WinDef.HWND[] windowHandle = new WinDef.HWND[1];
    User32.INSTANCE.EnumWindows(new WinUser.WNDENUMPROC() {
        @Override
        public boolean callback(WinDef.HWND hwnd, Pointer pointer) {
            if (matches(hwnd)) {
                windowHandle[0] = hwnd;
                return false;
            }
            return true;
        }
    }, Pointer.NULL);
    
    // Minimize or maximize windowHandle[0] here...
    

提交回复
热议问题