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

2
  • By "give this program focus" do you mean your program or the program you just launched? Commented Nov 15, 2009 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. Commented Nov 17, 2009 at 10:25

4 Answers 4

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

Sign up to request clarification or add additional context in comments.

Comments

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.

1 Comment

Gold says the program starts, but doesn't get the focus. (In another question, that's now been closed as a duplicate)
0

Process.Start()??

Comments

0

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

Process.Start("path");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.