Find window with specific text for a Process
Posted
by Axarydax
on Stack Overflow
See other posts from Stack Overflow
or by Axarydax
Published on 2010-04-27T08:30:33Z
Indexed on
2010/04/27
8:33 UTC
Read the original article
Hit count: 214
Hello, I'm trying to find if a window with specific has been open by a Process. That process spawns multiple windows, and I need to check them all.
I have no trouble finding the process, with
foreach (Process p in Process.GetProcesses())
{
if (p.MainModule.FileName.ToLower().EndsWith("foo.exe"))
FindChildWindowWithText(p); //do work
the problem is what to do next. I cannot use Process' MainWindowText
, because it changes with whichever window is activated.
Then I've tried to use Windows function EnumChildWindows
and GetWindowText
, but I am not sure if I'm passing a correct handle to EnumChildWindows. The EnumChildWindows
works as expected when passed MainWindowHandle, but of course the MainWindowHandle changes with active window. So I passed Process.Handle
, but I get different handles and different results when switching the app's windows. (I understand that EnumChildWindows returns handles to not only windows, but controls in .net speak, that's no problem if I could get the caption of the window too)
Maybe I am doing this the wrong way and I need a different approach - again, my problem is as simple as finding a window with text that matches specific regular expression. So I would probably need a function that enumerates all windows, that are visible in the taskbar or so.
Thanks
© Stack Overflow or respective owner