# HG changeset patch # User paulwerelds # Date 1285274699 0 # Node ID d5de6fa31bc6c06232f5a378cd90306025b24a27 # Parent fb66f749b7ff43382c6e4c281c739c331360275b Added an option to minimize on close. diff -r fb66f749b7ff -r d5de6fa31bc6 GUI/MainForm.Designer.cs --- a/GUI/MainForm.Designer.cs Wed Sep 22 20:44:34 2010 +0000 +++ b/GUI/MainForm.Designer.cs Thu Sep 23 20:44:59 2010 +0000 @@ -92,6 +92,7 @@ this.optionsMenuItem = new System.Windows.Forms.MenuItem(); this.startMinMenuItem = new System.Windows.Forms.MenuItem(); this.minTrayMenuItem = new System.Windows.Forms.MenuItem(); + this.minCloseMenuItem = new System.Windows.Forms.MenuItem(); this.startupMenuItem = new System.Windows.Forms.MenuItem(); this.separatorMenuItem = new System.Windows.Forms.MenuItem(); this.temperatureUnitsMenuItem = new System.Windows.Forms.MenuItem(); @@ -302,6 +303,7 @@ this.optionsMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.startMinMenuItem, this.minTrayMenuItem, + this.minCloseMenuItem, this.startupMenuItem, this.separatorMenuItem, this.temperatureUnitsMenuItem, @@ -319,19 +321,24 @@ this.minTrayMenuItem.Index = 1; this.minTrayMenuItem.Text = "Minimize To Tray"; // + // minCloseMenuItem + // + this.minCloseMenuItem.Index = 2; + this.minCloseMenuItem.Text = "Minimize On Close"; + // // startupMenuItem // - this.startupMenuItem.Index = 2; + this.startupMenuItem.Index = 3; this.startupMenuItem.Text = "Run On Windows Startup"; // // separatorMenuItem // - this.separatorMenuItem.Index = 3; + this.separatorMenuItem.Index = 4; this.separatorMenuItem.Text = "-"; // // temperatureUnitsMenuItem // - this.temperatureUnitsMenuItem.Index = 4; + this.temperatureUnitsMenuItem.Index = 5; this.temperatureUnitsMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.celciusMenuItem, this.fahrenheitMenuItem}); @@ -351,12 +358,12 @@ // // MenuItem4 // - this.MenuItem4.Index = 5; + this.MenuItem4.Index = 6; this.MenuItem4.Text = "-"; // // hddMenuItem // - this.hddMenuItem.Index = 6; + this.hddMenuItem.Index = 7; this.hddMenuItem.Text = "Read HDD sensors"; // // helpMenuItem @@ -513,6 +520,7 @@ private System.Windows.Forms.MenuItem resetMinMaxMenuItem; private System.Windows.Forms.MenuItem MenuItem3; private System.Windows.Forms.MenuItem gadgetMenuItem; + private System.Windows.Forms.MenuItem minCloseMenuItem; } } diff -r fb66f749b7ff -r d5de6fa31bc6 GUI/MainForm.cs --- a/GUI/MainForm.cs Wed Sep 22 20:44:34 2010 +0000 +++ b/GUI/MainForm.cs Thu Sep 23 20:44:59 2010 +0000 @@ -71,6 +71,7 @@ private UserOption showMax; private UserOption startMinimized; private UserOption minimizeToTray; + private UserOption minimizeOnClose; private UserOption autoStart; private UserOption readHddSensors; private UserOption showGadget; @@ -80,14 +81,14 @@ this.settings = new PersistentSettings(); this.settings.Load(Path.ChangeExtension( - System.Windows.Forms.Application.ExecutablePath, ".config")); + Application.ExecutablePath, ".config")); this.unitManager = new UnitManager(settings); // set the DockStyle here, to avoid conflicts with the MainMenu this.splitContainer.Dock = DockStyle.Fill; - int p = (int)System.Environment.OSVersion.Platform; + int p = (int)Environment.OSVersion.Platform; if ((p == 4) || (p == 128)) { splitContainer.BorderStyle = BorderStyle.None; splitContainer.Border3DStyle = Border3DStyle.Adjust; @@ -196,6 +197,8 @@ systemTray.IsMainIconEnabled = minimizeToTray.Value; }; + minimizeOnClose = new UserOption("minCloseMenuItem", false, minCloseMenuItem, settings); + autoStart = new UserOption(null, startupManager.Startup, startupMenuItem, settings); autoStart.Changed += delegate(object sender, EventArgs e) { try { @@ -320,7 +323,7 @@ } private void exitClick(object sender, EventArgs e) { - Close(); + Close(); } private void timer_Tick(object sender, EventArgs e) { @@ -347,7 +350,7 @@ System.Windows.Forms.Application.ExecutablePath, ".config")); } - private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { + private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { Visible = false; SaveConfiguration(); @@ -447,9 +450,25 @@ protected override void WndProc(ref Message m) { const int WM_SYSCOMMAND = 0x112; const int SC_MINIMIZE = 0xF020; + const int SC_CLOSE = 0xF060; + if (minimizeToTray.Value && m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) { SysTrayHideShow(); + } else if(minimizeOnClose.Value && + m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_CLOSE) { + /* + * Apparently the user wants to minimize rather than close + * Now we still need to check if we're going to the tray or not + * + * Note: the correct way to do this would be to send out SC_MINIMIZE, + * but since the code here is so simple, + * that would just be a waste of time. + */ + if (minimizeToTray.Value) + SysTrayHideShow(); + else + WindowState = FormWindowState.Minimized; } else { base.WndProc(ref m); }