C#将非关联应用程序带到前台
我一直在网上搜索答案,以便把一个程序放到前台。我一直在用SendKeys发送alt-tab键,以贫民窟的方式来做这件事。我试过了,但没用C#将非关联应用程序带到前台,c#,foreground,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 stati
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);
}
}
什么不起作用?你看到消息框了吗?也许你可以在这里找到更多信息不,消息框没有出现