How to open program through C# program (Windows Mobile) and give this program focus ?
EDIT by MarkJ: Gold says thanks for Process.Start suggestions, but for some reason the program still doesn't get the focus.
Thanks in advance, Gold
How to open program through C# program (Windows Mobile) and give this program focus ?
EDIT by MarkJ: Gold says thanks for Process.Start suggestions, but for some reason the program still doesn't get the focus.
Thanks in advance, Gold
You can use Process.Start();
to start your process and then:
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
public static bool BringWindowToTop(string windowName, bool wait)
{
int hWnd = FindWindow(windowName, wait);
if (hWnd != 0)
{
return SetForegroundWindow((IntPtr)hWnd);
}
return false;
}
To find window and bring it to front
You can launch a program by calling Process.Start
, like this:
Process.Start(programPath);
You can also pass in a file (eg, a Word document), or even a web site, and it will automatically launch in the default program for that file type on the user's machine.
When you call Process.Start
, the program should automatically receive focus.
Using the code below should automatically put the window on top.
Process.Start("path");