1

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

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
Gold
  • 60,526
  • 100
  • 215
  • 315
  • By "give this program focus" do you mean your program or the program you just launched? – SLaks Nov 15 '09 at 14:49
  • Have you set the TopMost property of the Form in the original application to true? If so, the program you start will not be visible. – heijp06 Nov 17 '09 at 10:25

4 Answers4

3

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

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
user211416
  • 111
  • 2
2

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.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • Gold says the program starts, but doesn't get the focus. (In another question, that's now been closed as a duplicate) – MarkJ Nov 17 '09 at 10:24
0

Process.Start()??

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
0

Using the code below should automatically put the window on top.

Process.Start("path");
MonkeyLogik
  • 87
  • 1
  • 1
  • 5