Reputation: 339
Let's say I have 2 pdf documents and I've opened them with acrobat fine reader. So I have 2 different windows. But when I use this code:
foreach (Process p in Process.GetProcesses("."))
{
try
{
Console.WriteLine("\r\n");
Console.WriteLine("\r\n Window Title:" + p.MainWindowTitle.ToString());
Console.WriteLine("\r\n Process Name:" + p.ProcessName.ToString());
Console.WriteLine("\r\n Window Handle:" + p.MainWindowHandle.ToString());
Console.WriteLine("\r\n Memory Allocation:" + p.PrivateMemorySize64.ToString());
}
catch { }
}
It gives me only the last selected window of acrobat. But I need both of them, thank you.
Upvotes: 2
Views: 128
Reputation: 564433
The Process
will only provide the "main" window handle, not each window.
You can accomplish this via the Windows API and PInvoke, however. EnumWindows will let you enumerate the windows opened on the system. You can then use GetWindowThreadProcessId to see if the Window belongs to your process.
At that point, you'll have the window handle for each window of the process. Using the Handle, you can call GetWindowText to get the window title.
Upvotes: 4