[ACCEPTED]-Make a running process the active Window-ms-access
Accepted answer
Eric's answer didn't work for me. I found 5 a better solution here on SO with SetForegroundWindow. First 4 I wondered, why it one time worked, next 3 time it did'n.Then I excluded the current 2 process from the list. So, here's my final 1 version:
static void BringWindowToFront()
{
var currentProcess = Process.GetCurrentProcess();
var processes = Process.GetProcessesByName(currentProcess.ProcessName);
var process = processes.FirstOrDefault(p => p.Id!=currentProcess.Id);
if (process == null) return;
SetForegroundWindow(process.MainWindowHandle);
}
[DllImport("user32.dll")]
static extern bool SetForegroundWindow(IntPtr hWnd);
Try this:
[DllImport("user32.dll", CharSet=CharSet.Auto,ExactSpelling=true)]
public static extern IntPtr SetFocus(HandleRef hWnd);
[TestMethod]
public void PlayAround()
{
Process[] processList = Process.GetProcesses();
foreach (Process theProcess in processList)
{
string processName = theProcess.ProcessName;
string mainWindowTitle = theProcess.MainWindowTitle;
SetFocus(new HandleRef(null, theProcess.MainWindowHandle));
}
}
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.