Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a c# equivalent of m_nCmdShow?

Tags:

c#

In an MFC program, you can determine whether the application shortcut had the Run value set to "Minimized" by checking the value of m_nCmdShow. Is there an equivalent way to do this in c#?

To clarify, I don't want to set the state of a particular form. If you look at the properties for a shortcut, there is a "Run" option. You can set this value to Normal Window, Minimized, or Maximized.

In C++ you can read what that startup value was set to by looking at m_nCmdShow. I need to do the same thing in C#.

Update

This attempt:

[STAThread]
static void Main(string[] args)
{
    ProcessStartInfo processInfo = Process.GetCurrentProcess().StartInfo;
    MessageBox.Show(processInfo.WindowStyle.ToString());
    ...
}

always reports Normal, no matter what the shortcut is set to.

like image 783
lfalin Avatar asked Sep 14 '11 16:09

lfalin


1 Answers

In WindowsForms its the WindowState property of Form class. check it up in properties at design time or set it from code.

Edit: When running the program from a shortcut Windows is likely to use the CreateProcess API passing a STARTUPINFO structure to it.

from your Windows Forms application you get such structure in this way:

System.Diagnostics.Process.GetCurrentProcess().StartInfo

which contains the property: WindowStyle and the available values for it are those of the enum:

System.Diagnostics.ProcessWindowStyle

so:

Hidden;
Minimized;
Maximized;
Normal;

and that's the mapping to m_nCmdShow the OP is looking for.

like image 62
Davide Piras Avatar answered Sep 20 '22 09:09

Davide Piras