java - 如何使用java查找正在运行的应用程序处于最小化状态?

标签 java windows jna

如何使用java查找windows桌面所有正在运行的应用程序都处于最小化状态?

最佳答案

你需要先download jna.jarplatform.jar 并将它们添加到您的类路径中。您可以通过查看 MSDN documentation 来确定要进行的 Windows 系统调用。 .

下面是枚举所有最小化窗口的代码:

import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser.WINDOWINFO;
import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;

public class Minimized {
    private static final int MAX_TITLE_LENGTH = 1024;
    private static final int WS_ICONIC = 0x20000000;

    public static void main(String[] args) throws Exception {
        User32.EnumWindows(new WNDENUMPROC() {
            @Override
            public boolean callback(HWND arg0, Pointer arg1) {
                WINDOWINFO info = new WINDOWINFO();
                User32.GetWindowInfo(arg0, info);

                // print out the title of minimized (WS_ICONIC) windows
                if ((info.dwStyle & WS_ICONIC) == WS_ICONIC) {
                    byte[] buffer = new byte[MAX_TITLE_LENGTH];
                    User32.GetWindowTextA(arg0, buffer, buffer.length);
                    String title = Native.toString(buffer);
                    System.out.println("Minimized window = " + title);
                }
                return true;
            }
        }, 0);
    }

    static class User32 {
        static { Native.register("user32"); }
        static native boolean EnumWindows(WNDENUMPROC wndenumproc, int lParam);
        static native void GetWindowTextA(HWND hWnd, byte[] buffer, int buflen);
        static native boolean GetWindowInfo(HWND hWnd, WINDOWINFO lpwndpl);
    }
}

关于java - 如何使用java查找正在运行的应用程序处于最小化状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11328743/

相关文章:

java - skmap 自定义注解首次加载大小翻倍

java - 来自服务器的错误 : Data source rejected establishment of connection, 消息: "Too many connections"

windows - 如何在 Windows 中杀死 glassfish 服务器?

c# - 如何控制网络客户端电脑

java - 如何纠正 Native.loadlibrary 错误

macos - 来自 root 的 mac os java 版本不同

java - @Inject 和@PostConstruct 不能在单例模式下工作

java - 从当前进程获取hWnd

c++ - 不打开窗口的 OpenGL 上下文 - 当使用由 GetDesktopWindow 制作的 HWND 时,wglMakeCurrent 因 HDC 和 HGLRC 而失败

java - 如何从类路径中删除 JNA.jar?