I have developed a windows form application and installer for it. I had installed that app on my machine. Now when I restart my PC or Log in on machine the App gets launched and shown on desktop. A sys tray icon is also shown in sys-tray. Now I want to keep app hidden and only sys tray icon should be visible. Means app should not be displayed on screen but sys tray icon should be visible. I have used "CreateProcessAsCurrentUser" method in which I have set the value of "STARTF_USESHOWWINDOW" to different values. But still its not working. Also I am not getting which method of Application gets called on System startup. Is it Main() function from Program.cs file. Please tell me the solution and also the Function which gets called.
[STAThread]
Main() function code: `static void Main()
{
Mutex mutex = new Mutex(false, "Application Name");
try
{
if (mutex.WaitOne(0, false))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.Run(new MainForm());
}
else
{
IntPtr pf = NativeMethods.FindWindow(null, "Application Name");
NativeMethods.ShowWindow(pf, 0);
NativeMethods.SetForegroundWindow(pf);
}
}
I have set the value of flag as below.
[Flags]
public enum CreateProcessFlags : uint
{
STARTF_USESHOWWINDOW = 0x00000000,
}