I would advise to use
System.Diagnostics.Process
, see
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[
^].
When a process is started successfully, use the property if the
Process
instance
Process.MainWindowHandle
, see
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx[
^].
Pay attention for the exceptions thrown by this property. Makes sure you process all exceptions immediately to detect the situation when the process is not yet started, already terminated, etc. If it happens or null is returned, it may mean that the handle is not yet created; in this case, try again later (yes, not perfectly effective, but you don't have another event or criterion).
When you obtain a window handle, move the application using P/Invoked raw Windows API
MoveWindow
,
SetWindowPos
or
SetWindowPlacement
or combination of those. I suggests the variants because you might need to put the window in proper Z-order position, adjust its size and handle the situations when the application is "reluctant" to assume exactly desired size, etc.
Please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.mainwindowhandle.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=VS.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633544%28v=VS.85%29.aspx[
^],
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632611%28v=VS.85%29.aspx[
^].
If you are yet to learn P/Invoke, read this:
http://en.wikipedia.org/wiki/P/Invoke[
^],
http://msdn.microsoft.com/en-us/library/Aa712982[
^].
Here you will be able to find already invoked code of those and other functions:
http://www.pinvoke.net/[
^].
Also, this CodeProject article can be helpful:
Essential P/Invoke[
^].
That's it.
—SA