Lzzzra
Lzzzra

Reputation: 21

C#: Get WindowHandles of all windows by Processname

there is a application with 5 windows. i have the PID of that process, and how can i get all WindowHandles of that Process?

thanks.

Upvotes: 2

Views: 487

Answers (3)

Jahan Zinedine
Jahan Zinedine

Reputation: 14874

Get the MainWindowHandle and then call EnumChildWindows on it.

Maybe calling managed code will be better than PInvoke, you can find more here Managed Windows API

Upvotes: 1

Andrei Andrushkevich
Andrei Andrushkevich

Reputation: 9973

User something like this:

Process[] processes = Process.GetProcesses(".");
foreach (var process in processes)
{
    var handle = process.MainWindowHandle;
}

Upvotes: 0

Uwe Keim
Uwe Keim

Reputation: 40736

Start with some PInvoke stuff described in this MSDN article.

Upvotes: 0

Related Questions