tags:

views:

1151

answers:

2
+2  A: 

Actually Process.MainWindowHandle is a handle of top-most window, it's not really the "Main Window Handle"

aku
+6  A: 

@edg,

I guess it's an error in MSDN. You can clearly see in Relfector, that "Main window" check in .NET looks like:

private bool IsMainWindow(IntPtr handle)
{
    return (!(NativeMethods.GetWindow(new HandleRef(this, handle), 4) != IntPtr.Zero)  
             && NativeMethods.IsWindowVisible(new HandleRef(this, handle)));
}

When .NET code enumerates windows, it's pretty obvious that first visible window (i.e. top level window) will match this criteria.

aku