-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
The Process.MainWindowHandle currently grabs the first window that 1) does not have owner 2) is visible:
runtime/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs
Lines 43 to 46 in 7715391
| private static bool IsMainWindow(IntPtr handle) | |
| { | |
| return (Interop.User32.GetWindow(handle, GW_OWNER) == IntPtr.Zero) && Interop.User32.IsWindowVisible(handle) != Interop.BOOL.FALSE; | |
| } |
Arguably if the process has multiple windows meeting this criteria with one of them having WS_POPUP, the popup is probably not the main window.
Reproduction Steps
Create a process with normal and a popup window. The repro relies on EnumWindow returning the popup first, but the order is not guaranteed.
Expected behavior
Popup windows are returned as main window even when non-popup windows exist.
Actual behavior
Prefer non-popup windows.
Regression?
No, same in .NET Framework.
Known Workarounds
Do not use Process.MainWindowHandle but do your own interop.
Configuration
.NET: not specific
OS: not specific (27793 x64)
Other information
No response