static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Check for any passed arguments if (args.Length > 0) { switch (args[0].ToLower().Trim().Substring(0, 2)) { // Preview the screen saver case "/p": // args[1] is the handle to the preview window ScreenSaverForm screenSaverForm = new ScreenSaverForm(new IntPtr(long.Parse(args[1]))); screenSaverForm.ShowDialog(); Application.Run(); break; // Show the screen saver case "/s": RunScreensaver(); break; // Configure the screesaver's settings case "/c": // Show the settings form SettingsForm settingsForm = new SettingsForm(); settingsForm.ShowDialog(); break; // Show the screen saver default: RunScreensaver(); break; } } else { // No arguments were passed so we show the screensaver anyway RunScreensaver(); } }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length > 0) { string firstArgument = args[0].ToUpperInvariant().Trim(); string secondArgument = args.Length > 1 ? args[1].Trim() : null; // Handle cases where arguments are separated by colon. // Examples: /C:1234567 or /P:1234567 if (firstArgument.Length > 2) { secondArgument = firstArgument.Substring(3).Trim(); firstArgument = firstArgument.Substring(0, 2); } if (firstArgument == "/C") // Configuration mode { using (SettingsForm settingsForm = new SettingsForm()) { Application.Run(settingsForm); } } else if (firstArgument == "/P") // Preview mode { IntPtr previewWndHandle; if (secondArgument == null) { previewWndHandle = NativeMethods.GetDesktopWindow(); } else { previewWndHandle = new IntPtr(long.Parse(secondArgument, CultureInfo.InvariantCulture)); } // Do not show cities in preview mode using (MainForm mainForm = new MainForm(null, previewWndHandle, false, false, null)) { Application.Run(mainForm); } } else if (firstArgument == "/S") // Full-screen mode { ShowScreenSaver(); Application.Run(); } else // Undefined argument { MessageBox.Show("Sorry, but the command line argument \"" + firstArgument + "\" is not valid.", "FlipIt", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else // No arguments - treat like /C { using (SettingsForm settingsForm = new SettingsForm()) { Application.Run(settingsForm); } } }