Reputation: 16724
There's a DialogBox raised by the WebBrowser
inside my application that I need to find. I tried this:
FindWindowEx(webBrowserEx1.Handle, IntPtr.Zero, "#32770", "title here")
but it does return IntPtr.Zero
it does works fine:
FindWindow("#32770", "title here")
But I want to search for the windows inside webBrowserEx1
control only and not a global search like does FindWindow()
Update: Using spy++ I can see that the DialogBox that the neither the DialogBox's first child window nor the owner is the WebBrowser
(I guess that's why it doesn't works) but the parent window is my own application (where the WebBrowser is hosted on) so I updated my code like this:
handle = FindWindowEx(this.Handle, IntPtr.Zero, "#32770", "title here");
but it didn't worked either.
Upvotes: 0
Views: 2725
Reputation: 94
It could be the Dialog is not a direct child of the WebBrowser
- maybe you can verify that with Spy++.
And just by coincidence just yesterday I stumbled across a piece of c# code I used years ago for recursively searching through child windows. Maybe that helps:
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
/// <summary>
/// Uses FindWindowEx() to recursively search for a child window with the given class and/or title.
/// </summary>
public static IntPtr FindChildWindow( IntPtr hwndParent, string lpszClass, string lpszTitle )
{
return FindChildWindow( hwndParent, IntPtr.Zero, lpszClass, lpszTitle );
}
/// <summary>
/// Uses FindWindowEx() to recursively search for a child window with the given class and/or title,
/// starting after a specified child window.
/// If lpszClass is null, it will match any class name. It's not case-sensitive.
/// If lpszTitle is null, it will match any window title.
/// </summary>
public static IntPtr FindChildWindow( IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszTitle )
{
// Try to find a match.
IntPtr hwnd = FindWindowEx( hwndParent, IntPtr.Zero, lpszClass, lpszTitle );
if ( hwnd == IntPtr.Zero )
{
// Search inside the children.
IntPtr hwndChild = FindWindowEx( hwndParent, IntPtr.Zero, null, null );
while ( hwndChild != IntPtr.Zero && hwnd == IntPtr.Zero )
{
hwnd = FindChildWindow( hwndChild, IntPtr.Zero, lpszClass, lpszTitle );
if ( hwnd == IntPtr.Zero )
{
// If we didn't find it yet, check the next child.
hwndChild = FindWindowEx( hwndParent, hwndChild, null, null );
}
}
}
return hwnd;
}
Upvotes: 2