views:

214

answers:

3

Hello,

is there any way to start/lunch a program through Process in another screen?

some one asked that here but there was no answer

note: it is not a form in my app, I'm asking about running an external program in another screen!

cheers

+2  A: 

You would need to start the process, get the processes main window and use an API call like SetWindowPos() to move the window to the screen you want.

Lloyd
+5  A: 

Since the window is not yours, you can only move it by invoking the Windows API. You will have to do this:

  • Launch the process.

  • Use FindWindow to retrieve the handle to the window. If the window doesn’t exist yet, the process hasn’t created it yet; sleep for 500ms and then try again. (But don’t go into an infinite loop; stop if you can’t find the window after a reasonable timeout.)

  • Use SetWindowPos to change the position of the window.

If you don’t know the title of the window, you can’t use FindWindow. In that case,

  • Launch the process and get the process handle by retrieving Process.Handle.

  • Use EnumWindows to retrieve all the windows. For each window, use GetWindowThreadProcessId to check whether it belongs to your process. If no window belongs to your process, wait and keep trying.

  • Use SetWindowPos to change the position of the window.

Of course, you can use Screen.AllScreens[n].WorkingArea to retrieve the position and size of the screen you want, and then you can position the window relative to that.

Timwi
+2  A: 

First get out the area of the second monitor using something like:

Rectangle area = Screen.AllScreens[1].WorkingArea;

The use the Windows API SetWindowPos to move it, using the Process.MainWindowHandle you got from the starting of the other process as the handle.

ho1