Start and minimize another application

J

JezB

From within my .NET forms application I want to start and minimize another
application, so I go:

string eprog =
System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) +
@"\EvilLyrics\EvilLyrics.exe";
if (File.Exists(eprog))
{
ProcessStartInfo psi = new ProcessStartInfo(eprog);
psi.UseShellExecute = false;
psi.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(psi);
}

This starts the other application OK but doesn't minimize the window. Why?

Do I have to minimize the other application via Interop? If so how?
 
S

Stoitcho Goutsev \(100\)

JezB,

What is the other application? Is it managed? When windows starts an
application and call on its WinMain method it passes the preferable state as
a parameter. Whether or not the application will respect this is up to the
application itself. It may do that or not. Usually if there is some
framework used to create the application the framework take into account
this parameter.

What I suggest to try is to create a shortcut to this applciation and in the
shortcut properties to set that you want the application to run minimized.
Run the application (from windows, not from your program) and see how it
starts. If it start in normal window mode that means the application is
written in a way that it disrepsects the user's preferences. If this is the
case when you start the process wait until the message loop is up and
running - Process.WaitForInputIdle, then get the process main window -
Process.MainWindowHandle and use it with some of the API methods to change
the window state. There are more that one APIs that can do that, but the
easies I believe is ShowWindow.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top