System.Diagnostics.
Process myProcess = new System.Diagnostics.Process();myProcess.StartInfo.FileName =
"D:\\Program Files\\InterVideo\\WinDVR\\WinDvr.exe";myProcess.StartInfo.UseShellExecute =
false;myProcess.Start();
myProcess.WaitForInputIdle(2000);
IntPtr hWnd = myProcess.MainWindowHandle; //Console.WriteLine(hWnd); MessageBox.Show(hWnd.ToString());SetForegroundWindow(hWnd);
bool p = SetForegroundWindow(hWnd); if (!p) MessageBox.Show("Could not set focus"); SendKeys.SendWait("{Home}");}
[
DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool SetForegroundWindow(IntPtr hWnd);[
DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr SetFocus(IntPtr hWnd); Iam opening a mediaplayer windvr using the above code after that im sending {Home} key to the mediaplayer using sendkeys.send("{Home}") but keyboard focus is not on mediaplayerplss help me how to set the keyboard focus to the process starting with process.start()
thanks,
pramod
Bechir BejaouiPosted Mar 9, 2009, 12:47 PM
you have to use
myProcess.StartInfo.Verb
or
myProcess.StartInfo.Verbs
To indicate what exactly you want your process do