使用java处理外部窗口 [英] Handle external windows using java

查看:226
本文介绍了使用java处理外部窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查一个外部窗口(另一个java程序,但不是由我正在处理的程序控制)是否使用标题打开,如果打开,则根据用户最大化或最小化它Java中的命令(我只知道窗口的标题,没有别的)。 Google只说我可以使用 winapi 获取窗口句柄并使用句柄操作它,但我无法找到如何执行此操作。

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 maximize or minimize it based on the user command in Java (I know only the title of the window and nothing else) . Google only says that I can use winapi to get the window handle and manipulate it using the handle, but I'm not able to find how to do this.

我可以在这里找到关于如何使用JNI的参考资料:
在Java Swing中如何获得对窗口的Win32窗口句柄(hwnd)引用?。是否可以在不使用JNI的情况下执行此操作?

I could find references on how to do it using JNI here: In Java Swing how do you get a Win32 window handle (hwnd) reference to a window?. Is it possible to do this without using JNI?

有人可以帮助我了解如何执行此操作。

Could someone help me understand how to do this.

谢谢和问候

推荐答案

我刚刚在JNA 的。您可以在此处查看详细信息。

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...

这篇关于使用java处理外部窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆