.NET(C#):获取子窗口时,你只有一个进程句柄或PID? [英] .NET (C#): Getting child windows when you only have a process handle or PID?

查看:493
本文介绍了.NET(C#):获取子窗口时,你只有一个进程句柄或PID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

样的一种特殊情况的问题:

Kind of a special case problem:

  • 在我开始一个进程 System.Diagnostics.Process.Start(..)
  • 在该进程打开初始屏幕 - 此初始屏幕将成为主窗口
  • 在初始屏幕关闭,'真正的'用户界面显示。主窗口(闪屏)现在是无效的。
  • 我仍然有Process对象,我可以查询其句柄,模块等,但主要窗口句柄现在是无效的。
  • I start a process with System.Diagnostics.Process.Start(..)
  • The process opens a splash screen -- this splash screen becomes the main window.
  • The splash screen closes and the 'real' UI is shown. The main window (splash screen) is now invalid.
  • I still have the Process object, and I can query its handle, module, etc. But the main window handle is now invalid.

我需要得到流程的用户界面(UI或处理)在这一点上。假设我不能改变的过程中的行为,使这更容易(或更理智)。

I need to get the process's UI (or UI handle) at this point. Assume I cannot change the behavior of the process to make this any easier (or saner).

我环顾四周,在线,但我承认我没有看一个多小时。好像它应该是有点微不足道: - (

I have looked around online but I'll admit I didn't look for more than an hour. Seemed like it should be somewhat trivial :-(

推荐答案

如果你不介意使用Windows API,你可以使用的 EnumWindowsProc 和检查每个手柄的是,使用的 GetWindowThreadProcessId (一看就知道它在你的进程),那么也许 IsWindowVisible GetWindowCaption GetWindowTextLength 来确定哪些的hWnd 在你的过程是一个你想要的。

If you don't mind using the Windows API, you could use EnumWindowsProc, and check each of the handles that that turns up using GetWindowThreadProcessId (to see that it's in your process), and then maybe IsWindowVisible, GetWindowCaption and GetWindowTextLength to determine which hWnd in your process is the one you want.

但如果你还没有使用这些功能之前,这种做法将是一个正确的痛苦,所以希望有一个简单的方法。

Though if you haven't used those functions before that approach will be a right pain, so hopefully there's a simpler way.

这篇关于.NET(C#):获取子窗口时,你只有一个进程句柄或PID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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