I\'ve been trying to understand Process.MainWindowHandle.
According to MSDN; \"The main window is the window that is created when the process is started. After initi
Actually Process.MainWindowHandle is a handle of top-most window, it's not really the "Main Window Handle"
@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.