C#将无关联的应用程序带到前台

时间:2016-01-31 06:06:02

标签: c# foreground

我一直在网上寻找答案,让程序到达前台。我一直在通过发送带有SendKeys的alt-tab键击来实现这种贫民窟。我试过这个并没有用,

private void execute()
{
    setApp("League of Legends.exe");
    Thread.Sleep(1500);
}

[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
private static void setApp(String filename)
{
    Process[] SameProcesses = Process.GetProcessesByName(filename);
    Process SameProcess = SameProcesses[0];
    if (SameProcess.Equals(null))
    {
        System.Windows.Forms.MessageBox.Show("No process");
    }
    else
    { 
        SetForegroundWindow(SameProcess.MainWindowHandle); 
    }
}

0 个答案:

没有答案