A Windows systray application that displays the current lunar phase.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.2 KiB

using System;
using System.Drawing;
using System.Globalization;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using LunaWin.Properties;
namespace LunaWin
{
class LunaIcon : IDisposable
{
[DllImport("UXTheme.dll", EntryPoint = "#138")]
public static extern bool IsDarkMode();
// Instantiate the icon object
public LunaIcon()
{
//Globals.lunaIcon = new NotifyIcon();
}
// Display the icon in the systray
// Invoke at application launch
// Probably re-invoke when icon should be updated
public void Display()
{
// TextInfo object for accessing ToTitleCase
TextInfo txtInf = new CultureInfo("en-US", false).TextInfo;
// get the current lunar phase
LunaCalc lunaCalc = new LunaCalc();
LunaPhase currentPhase = lunaCalc.CurrentPhase();
// set icon resource name
string IconName = txtInf.ToTitleCase(currentPhase.Id);
OperatingSystem TheSystem = Environment.OSVersion;
switch (TheSystem.Version.Major)
{
// windows 10 and 11 support light/dark modes
case(10): case(11):
IconName += IsDarkMode() ? "Dark" : "Light";
break;
// windows 8 is dark only
case(8):
IconName += "Dark";
break;
// windows vista and 7 use color icons
default:
IconName += "Color";
break;
}
// set the icon resource
Globals.lunaIcon.Icon = Resources.ResourceManager.GetObject(IconName) as Icon;
// set the tooltip
Globals.lunaIcon.Text = currentPhase.Name;
// set the context menu
Globals.lunaIcon.ContextMenuStrip = new LunaMenu().CreateMenu();
// set icon visibility
Globals.lunaIcon.Visible = true;
}
// Dispose of object instance on exit
public void Dispose()
{
Globals.lunaIcon.Dispose();
}
}
}