Bring to forward window when minimized

我的梦境 提交于 2019-11-28 12:22:54

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

    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);
    }

You can use ShowWindow combined with what you already have, here is your example with a little modification:

    int IdRemoto = int.Parse(textBoxID.Text);

    Process[] processlist = Process.GetProcessesByName("AA_v3.3");

    foreach (Process process in processlist)
    {
        if (!String.IsNullOrEmpty(process.MainWindowTitle))
        {
            if (IdRemoto.ToString() == process.MainWindowTitle)
            {
                ShowWindow(process.MainWindowHandle, 9);
                SetForegroundWindow(process.MainWindowHandle);  
            }
        }
    }


   [DllImport("user32.dll")]
   private static extern bool SetForegroundWindow(IntPtr hWnd);
   [DllImport("user32.dll")]
   private static extern bool ShowWindow(IntPtr hWind, int nCmdShow);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!