Reputation: 2463
What is the best way to manage an external windows application in C# (or .NET)?
So far my I've been able to launch a process using System.Diagnostics.Process, however this simply allows me to launch/kill a process. (from what I've gathered)
I noticed System.Diagnostics.Process has a CloseMainWindow() routine which will send a request to a process' window. Can I use this Process class to send different messages? (if so, can anyone point me in direction of where I can learn about these windows messages)
I need to be able to manage an external program and manipulate it the following ways: 1) Launch 2) Kill Process 3) Show Application (Fullscreen and in taskbar) 4) Hide Application (Fullscreen and in taskbar)
Further details: Windows 7, Restricted to .Net 3.5 Framework
Upvotes: 4
Views: 2165
Reputation: 44605
you can do all you want in different ways, once you start the process yourself or you find it in the list of running processes, using classes or methods of System.Diagnostics.Process
, then you can follow different options...
for example consider that once you have this handle: Process.MainWindowHandle
you can send messages to that handle, with SendMessage
and PostMessage
and this allows you to do very very much; or you can use PInvoke APIs like SetWindowPos
or ShowWindow
or SetWindowLong
and do basically really everything...
see this for example:
How to use the ShowWindow API to hide and show a form
I can send you more links but won't like to refer to the whole MSDN ;-)
Upvotes: 0
Reputation: 17139
You're going to need to use some Win32 P/Invoke stuff to send window messages in order to do what you want.
See this code sample on ShowWindow or SendMessage which tells an external window to show or hide itself. You'll first need to get the window handle you want with FindWindowEx.
Upvotes: 0
Reputation: 274
Try sending a message to that window. Take a look at SendMessage
. The messages you need are SW_MINIMIZE
,SW_RESTORE
and SW_SHOWMAXIMIZED
.
Upvotes: 0
Reputation: 25773
You might be able to use interop and use SendMessage to do all of your functionality. See this: http://pinvoke.net/default.aspx/user32.SendMessage
Upvotes: 2