可能是 Dialog 不是 Dialog 的直接子级WebBrowser
- 也许您可以使用 Spy++ 验证这一点。
巧合的是,就在昨天,我偶然发现了一段 c# 代码,我多年前使用它递归地搜索子窗口。也许这有帮助:
[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;
}