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.

114 lines
3.4 KiB

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LunaWin
{
class LunaMenu
{
/// <summary>
/// creates the context menu
/// </summary>
/// <returns></returns>
public ContextMenuStrip CreateMenu()
{
// create menu and add default items
ContextMenuStrip lunaMenu = new ContextMenuStrip();
ToolStripMenuItem itm;
ToolStripSeparator sep;
// startup setting
itm = new ToolStripMenuItem();
itm.Name = "itmStartup";
itm.Text = "Run at login";
itm.Checked = Globals.RunAtLogin;
itm.Click += new EventHandler(SetStartup);
lunaMenu.Items.Add(itm);
// about
itm = new ToolStripMenuItem();
itm.Text = "About LunaWin";
itm.Click += new EventHandler(ShowAbout);
lunaMenu.Items.Add(itm);
// separator
sep = new ToolStripSeparator();
lunaMenu.Items.Add(sep);
// exit
itm = new ToolStripMenuItem();
itm.Text = "Exit";
itm.Click += new EventHandler(ExitApp);
lunaMenu.Items.Add(itm);
return lunaMenu;
}
/// <summary>
/// sets the user's startup preference
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SetStartup(object sender, EventArgs e)
{
RegistryKey startKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (Globals.RunAtLogin)
{
// remove from startup
startKey.DeleteValue("LunaWin", false);
Globals.RunAtLogin = false;
} else
{
// add to startup
startKey.SetValue("LunaWin", Application.ExecutablePath);
Globals.RunAtLogin = true;
}
// set the context menu item's checked state
((ToolStripMenuItem)Globals.lunaIcon.ContextMenuStrip.Items["itmStartup"]).Checked = Globals.RunAtLogin;
}
public void GetStartup()
{
RegistryKey startKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
object startVal = startKey.GetValue("LunaWin");
if(startVal != null)
{
Globals.RunAtLogin = true;
} else
{
Globals.RunAtLogin = false;
}
}
/// <summary>
/// displays the about window
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ShowAbout(object sender, EventArgs e)
{
// show the about window
Globals.lunaForm.Show();
// bring about window to front
Globals.lunaForm.BringToFront();
}
/// <summary>
/// exits the application
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ExitApp(object sender, EventArgs e)
{
Application.Exit();
}
}
}