获取任务栏中的应用程序数量
多年来我一直想知道如何做到这一点。我正在创建一个小应用程序,我需要弄清楚任务栏中显示了多少个应用程序或窗口。
我还没有找到任何有关此的信息,我将不胜感激任何帮助。
谢谢 :)
I've been wondering how to do this for ages. I'm creating a little app, and I need to figure out how many apps or windows are displayed in the TaskBar.
I've yet to find any info on this at all, I'd appreciate any help at all.
Thank you :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这里是一篇文章,介绍了如何获取窗口,当您使用 ALT+TAB 组合键时显示。
基本上,您将获得与任务栏中显示的相同窗口(除非它是未显示的工具窗口),但话又说回来,您始终可以检查 WS_EX_TOOLWINDOW (未显示)和 <强>WS_EX_APPWINDOW(如图所示)。
Here is an article that shows how to get the windows, that are shown when you are using the ALT+TAB key combination.
Basically, you will get the same windows that are shown in the taskbar (unless it is a tool window that is not displayed), but then again, you can always check against WS_EX_TOOLWINDOW (not shown) and WS_EX_APPWINDOW (shown).
正如其他人所说,您需要使用 Win32 EnumWindows 函数枚举窗口,并以这种方式获得计数。
您还可以使用 Process.GetProcesses(); 枚举进程,但是像资源管理器窗口这样不是单独进程的窗口不会显示在该列表中。
As other's have said you need to enumerate through the windows using the Win32 EnumWindows function, and get your count that way.
You can also enumerate through processes using
Process.GetProcesses();
However windows like explorer windows which are not a separate process will not show up in that list.您可以查看我之前的答案 此处;这里的主要区别是您只需计算符合给定要求的窗口即可。
You may have a look at my previous answer here; the main difference here is that you just have to count the windows that match the given requirements.
据我所知,没有管理方法可以访问任务栏。这里有一个链接,描述了如何通过 Windows API 访问任务栏。但是,我快速扫描没有显示任何“项目数量”或类似的内容。尽管如此,它可能会为您指明正确的方向。
As far as I know there is no managed way of accessing the taskbar. Here is a link that describes how to access the taskbar by the Windows API. However, I a quick scan did not show any "number of items" or something similar. Still it might point you in the right direction.