I am trying to get the handle of a window from a process. Now, that process shows a splash screen, so, if i try ProcessInstance.MainWindowHandle all I get is the handle of that processes main window, that is the splash screen.
How can I find the window I want? Maybe if I could get a list of windows that process has I could pick the one I want.
Heres the code I am trying :
AutomationElement aeProcessInstance =
AutomationElement.FromHandle(mProcess.MainWindowHandle);
AutomationElement aeButton = aeProcessInstance.FindFirst(
TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, "Start"));
aeButton.SetFocus();
Thread.Sleep(1000);
SendKeys.SendWait("{ENTER}");
This is a challenging task. An application can have any number of top level windows. These can come and go as the application runs.
I see you are using SendKeys – are you writing an automation or test system? If so, you may want to look at the accepted answer to
this question.Could you better explain what you are trying to do? For example, are you working with random applications? Or is the target process something you have control over?
Update
Ok, your extra information means this problem is more tractable. You need to use Spy++, a debugger, or Xperf, Process Explorer, or some other tool to undertand the windowing and threading behavior.
Once you know that, you can then use various Window management functions to find the window you need and deal with it.
Also, be aware of the Windows Integrity Mechanism. The application you use to find windows in another process and send them messages must be at a higher Integrity Level (IL) that the driven application.