I've written an app that starts and monitors a number of processes. If
one of those processes dies, the app restarts it. One of the options
I've written hides the main window of the monitored process (since
there are 99 processes, I'm trying to keep the screen clutter to a
minimum). Basicly, I start the app, then minimize, maximize, show, or
hide it based on the option chosen. My problem comes with the actual
app I'm monitoring. It doesn't like the ShowWindow function, and it
doesn't respect the StartInfo.WindowStyle property. I have taken to
starting the app minimized, then using one of the following based on
the option given: (note, SW, WM, ans SC are enums with the appropriate
values, and prTarget is a System.Diagnostics.Process)
ShowWindow(prTarget.MainWindowHandle, SW.HIDE)
SendMessage(prTarget.MainWindowHandle, WM.SYSCOMMAND, SC.MAXIMIZE, 0)
SendMessage(prTarget.MainWindowHandle, WM.SYSCOMMAND, SC.MINIMIZE, 0)
SendMessage(prTarget.MainWindowHandle, WM.SYSCOMMAND, SC.RESTORE, 0)
Again, this works for every other application I've tried (testing by
monitoring notepad, charmap, calc, etc. on my computer). Prerviously,
I had been using ShowWindow calls to maximize, minimize, and restore,
but this caused wierd behavior with the production app. So my
questions are:
1. Is there a better way to hide the process?
2. Is there a way to get the current hidden, maximized, minimized,
restored state of the window from the process or MainWindowHandle?