Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 最小化时将窗口向前移动_C#_Window_Foreground - Fatal编程技术网

C# 最小化时将窗口向前移动

C# 最小化时将窗口向前移动,c#,window,foreground,C#,Window,Foreground,我想知道如何提出一个特定的窗口。 SetForegroundWindow在窗口未最小化时工作!!但是当最小化窗口时,SetForeGroundIndow不起作用 这是我的代码: int IdRemoto = int.Parse(textBoxID.Text); Process[] processlist = Process.GetProcessesByName("AA_v3.3"); foreach (Process process in pr

我想知道如何提出一个特定的窗口。 SetForegroundWindow在窗口未最小化时工作!!但是当最小化窗口时,SetForeGroundIndow不起作用

这是我的代码:

        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)
                    SetForegroundWindow(process.MainWindowHandle);  
            }
        }


[DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
您可以结合已有的内容使用,下面是您的示例,稍作修改:

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

您可以使用API检查窗口是否最小化,然后使用恢复窗口:

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