如何从进程id获取主窗口句柄? [英] How to get main window handle from process id?

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

问题描述

如何从进程ID获取窗口句柄?



我要将此窗口置于前端。

$

解决方案

我不相信Windows (相对于.NET)提供了一个直接的方式来获得。



我知道的唯一方法是枚举所有顶级窗口 EnumWindows(),然后找到每个属于 GetWindowThreadProcessID()的进程。这听起来间接和低效,但它并没有你所期望的那么糟 - 在一个典型的情况下,你可能有十几个顶级窗口走过...


How to get main window handle from process id?

I want to bring this window to the front.

It works well in "Process Explorer".

解决方案

I don't believe Windows (as opposed to .NET) provides a direct way to get that.

The only way I know of is to enumerate all the top level windows with EnumWindows() and then find what process each belongs to GetWindowThreadProcessID(). This sounds indirect and inefficient, but it's not as bad as you might expect -- in a typical case, you might have a dozen top level windows to walk through...

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

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