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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With