ScreensaverStars/ScreenSaver/Program.cs

89 lines
3.3 KiB
C#
Raw Permalink Normal View History

2022-09-03 23:45:44 -04:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace ScreenSaver
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (args.Length > 0)
{
string firstArgument = args[0].ToLower().Trim();
string secondArgument = 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);
}
else if (args.Length > 1)
secondArgument = args[1];
if (firstArgument == "/c") // Configuration mode
{
MessageBox.Show("There is no configuration for this screensaver");
}
else if (firstArgument == "/p") // Preview mode
{
if (secondArgument == null)
{
MessageBox.Show("Sorry, but the expected window handle was not provided.",
"ScreenSaver", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
IntPtr previewWndHandle = new IntPtr(long.Parse(secondArgument));
Application.Run(new ScreenSaverForm(previewWndHandle));
}
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.", "ScreenSaver",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
else // No arguments - treat like /c
{
MessageBox.Show("There is no configuration for this screensaver");
}
}
/// <summary>
/// Display the form on each of the computer's monitors.
/// </summary>
static void ShowScreenSaver()
{
int height = 0;
int width = 0;
foreach (var screen in System.Windows.Forms.Screen.AllScreens)
{
//take smallest height
height = screen.Bounds.Height;
width += screen.Bounds.Width;
}
ScreenSaverForm screensaver = new ScreenSaverForm(new System.Drawing.Rectangle(Screen.AllScreens[0].Bounds.X, Screen.AllScreens[0].Bounds.Y, width, height));
screensaver.Show();
}
}
}