Bring to forward window when minimized

前端 未结 2 453
北海茫月
北海茫月 2020-12-11 05:00

I want to know how to bring forward a particular window. SetForegroundWindow works when the window is not minimized!! but when a minimize the window, SetForegroundWindow doe

2条回答
  •  既然无缘
    2020-12-11 05:17

    You can check to see if the window is minimized using the IsIconic() API, then use ShowWindow() to restore it:

    public const int SW_RESTORE = 9;
    
    [DllImport("user32.dll")]
    public static extern bool IsIconic(IntPtr handle);
    
    [DllImport("user32.dll")]
    public static extern bool ShowWindow(IntPtr handle, int nCmdShow);
    
    [DllImport("user32.dll")]
    public static extern int SetForegroundWindow(IntPtr handle);
    
    private void BringToForeground(IntPtr extHandle)
    {
        if (IsIconic(extHandle))
        {
            ShowWindow(extHandle, SW_RESTORE);
        }
        SetForegroundWindow(extHandle);
    }
    

提交回复
热议问题