我正試圖恢復(甚至最大化)另一個應用程序,並從我的項目向它發送輸入。我可以爲Notepad
或Skype
等某些應用程序執行此操作,但不適用於其他應用程序,如TeamSpeak
。
任何想法爲什麼以及如何解決問題?將另一個應用程序放入前臺並向其發送輸入
這裏是我的代碼:
private void winact()
{
IntPtr hWnd; //change this to IntPtr
Process[] processRunning = Process.GetProcesses();
string title, name;
foreach (Process pr in processRunning)
{
title = pr.MainWindowTitle.ToLower();
name = pr.ProcessName.ToLower();
if (title.Contains("teamspeak".ToLower()) || name.Contains("teamspeak".ToLower()))
{
hWnd = pr.MainWindowHandle;
ShowWindow(hWnd, 3);
SetForegroundWindow(hWnd); //set to topmost
break;
}
}
}
我用InputSimulator發送輸入。
http://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf MyWindow.TopMost = true –
我想讓另一個進程成爲最頂級的進程,總是通過'winact()'設置,問題出在輸入 –
你試過'hWnd.Activate();'和'hWnd.TopMost = true;'?我認爲這應該足以獲得關鍵投入。 – ViVi