获取应用程序的窗口句柄 [英] Get Application's Window Handles

查看:652
本文介绍了获取应用程序的窗口句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建,鉴于另一个应用程序mainWindowhandle它收集有关窗口状态信息的应用程序。我没有问题,收集有关的子窗口的信息,但我不能访问应用程序,甚至菜单的其他打开的窗口。有没有办法得到一个应用程序的所有窗口句柄?

I'm building an app that given another app mainWindowhandle it collects information about the window state. I have no problem collecting information about child windows, but I can not access the other open windows of an application or even the menus. Is there any way of getting all window handles of an application?

推荐答案

您可以做 Process.MainWindowHandle 似乎做什么:使用P / Invoke来调用<一HREF =htt​​p://pinvoke.net/default.aspx/user32/EnumWindows.html> EnumWindows的 功能,调用回调方法,每顶-level窗口系统中的

You could do what Process.MainWindowHandle appears to do: use P/Invoke to call the EnumWindows function, which invokes a callback method for every top-level window in the system.

在你的回调,叫<一href="http://pinvoke.net/default.aspx/user32/GetWindowThreadProcessId.html"><$c$c>GetWindowThreadProcessId,和 Process.Id 比较窗口的进程ID;如果过程的ID匹配,则窗口句柄添加到列表。

In your callback, call GetWindowThreadProcessId, and compare the window's process id with Process.Id; if the process ids match, add the window handle to a list.

这篇关于获取应用程序的窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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