如何使用java代码在Windows(taskmanager - >应用程序)中打开应用程序列表? [英] How to get opened applications list in windows(taskmanager ->application) using java code?

查看:119
本文介绍了如何使用java代码在Windows(taskmanager - >应用程序)中打开应用程序列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我想要的快照!

我正在尝试在java中开发一个程序,它可以在任务栏中获取所有打开的应用程序。我尝试了很多链接但没有一个对我有帮助。 Ganesh Rangarajan在2013年7月也提出了同样的问题,但没有人回答他。这是他的问题

I am trying to develop a program in java which can get all opened application in the taskbar. I have tried many links but none of those are helpful to me. The same question was also asked by Ganesh Rangarajan in July 2013 but none has answered him. Here is his question.

推荐答案

以下是获取所有(可见,不可见)窗口标题的解决方案:
https://stackoverflow.com/a/11067492/6401177

Here is the solution to get titles of ALL (visible, non-visible) windows: https://stackoverflow.com/a/11067492/6401177

如果你想只获取打开的顶级窗口的标题(即应用程序任务栏),您必须检查每个窗口的可见性(和/或检查此处列出的其他条件: http://vb.mvps.org/articles/ap200003.asp )。虽然,检查窗口的可见性似乎已经足够了。

If you want to get titles of opened top-level windows only (i.e. Applications taskbar), you have to check the visibility of each window (and/or check other conditions as listed here: http://vb.mvps.org/articles/ap200003.asp). Although, checking window's visibility seems sufficient.

我刚才在以前的代码中改变了方法回调,如下所示:

I just altered method "callback" in previous code like this:

String wText = Native.toString(windowText, System.getProperty("file.encoding")).trim();
        com.sun.jna.platform.win32.WinDef.HWND hwnd_1 = new WinDef.HWND(hWnd);
        boolean b = com.sun.jna.platform.win32.User32.INSTANCE.IsWindowVisible(hwnd_1);
        if (!wText.isEmpty() && b) {
           windowNames.add(wText);
        }

我还添加了file.encoding,因此标题在非非正确显示英语Windows环境也是如此。
我测试了Windows XP / 7/8中的代码,效果很好。
唯一的问题似乎是一些名为程序管理器的默认内部(?)窗口总是包含在列表中。

I also added "file.encoding" so titles are shown correctly in non-english Windows environment too. I tested code in Windows XP/7/8 and it works nice. The only problem seems to be that some default internal(?) window called "Program Manager" is always included in the list.

你需要两个JAR( JNA图书馆来自: https://github.com/java-native-access/jna

You need both JARs (JNA libraries) from: https://github.com/java-native-access/jna

这篇关于如何使用java代码在Windows(taskmanager - >应用程序)中打开应用程序列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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