I am attempting to force focus on a windows modern application from another application programatically.
This can be done with windows desktop applications by importing the user32.dll and using the SetForegroundWindow method.
This works fine for desktop apps, but with modern / universal / windows store apps you cannot acquire the window handle from the process. The process can be acquired, but the window handle will be 0.
Here is example code that works for desktop applications. This code is only intended as an example.
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
public myMethod()
{
var myProc = Process.GetProcessesByName("nameOfModernAppaHere");
SetForegroundWindow(myProc[0].MainWindowHandle);
}
Does anyone know a way to force focus on a modern app?
Thanks