Unexpected behaviour of Process.MainWindowHandle

前端 未结 2 1571
礼貌的吻别
礼貌的吻别 2020-12-10 15:02

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

相关标签:
2条回答
  • 2020-12-10 15:11

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

    0 讨论(0)
  • 2020-12-10 15:18

    @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.

    0 讨论(0)
提交回复
热议问题