I want to toggle a process's visibility at runtime, I have a Windows Form app that starts via a process another console app hidden by default but I'd like to allow the admin user to toggle this state via a checkbox and show the console app if they choose.
I have this but it's not working:
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
ProcessWindowStyle state = cvarDataServiceProcess.StartInfo.WindowStyle;
if (state == ProcessWindowStyle.Hidden)
cvarDataServiceProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
else if (state == ProcessWindowStyle.Normal)
cvarDataServiceProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
}
You have to use Win32 API for this.
This, however, will not work when the process is started
hidden, because the window will not be created and the handle to main window will be zero (invalid).So, maybe you can start the process normally and then hide it after that. :)