Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET (C#): Getting child windows when you only have a process handle or PID?

Tags:

Kind of a special case problem:

  • 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.

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 :-(

like image 446
shea241 Avatar asked Sep 17 '08 01:09

shea241


People also ask

Is C# a .NET language?

C# is a programming language, . NET is a blanket term that tends to cover both the . NET Framework (an application framework library) and the Common Language Runtime which is the runtime in which . NET assemblies are run.

Why is C# so popular?

The popularity of C# is due to several reasons. The main one (as I mentioned before) is the community of developers and support for C# and the . NET framework in general. Being open-source makes it very easy to collaborate with other contributing developers.

What is .NET language?

. NET (pronounced dot net) is a framework that provides a programming guidelines that can be used to develop a wide range of applications–––from web to mobile to Windows-based applications. The . NET framework can work with several programming languages such as C#, VB.NET, C++ and F#.

Is .NET similar to C++?

There's no such thing as "C++.NET". There's C++/CLI, which is basically C++ with Microsoft extensions that allow you to write code targeting the . NET framework. C++/CLI code compiles to CLR bytecode, and runs on a virtual machine just like C#.


Video Answer


1 Answers

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 real pain, so hopefully there's a simpler way.

like image 94
MB. Avatar answered Sep 20 '22 04:09

MB.