Added an option to minimize on close.

This commit is contained in:
Paul Werelds 2010-09-23 20:44:59 +00:00
parent 1bd6b91c6f
commit acf99ee2d7
2 changed files with 36 additions and 9 deletions

View File

@ -92,6 +92,7 @@ namespace OpenHardwareMonitor.GUI {
this.optionsMenuItem = new System.Windows.Forms.MenuItem(); this.optionsMenuItem = new System.Windows.Forms.MenuItem();
this.startMinMenuItem = new System.Windows.Forms.MenuItem(); this.startMinMenuItem = new System.Windows.Forms.MenuItem();
this.minTrayMenuItem = 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.startupMenuItem = new System.Windows.Forms.MenuItem();
this.separatorMenuItem = new System.Windows.Forms.MenuItem(); this.separatorMenuItem = new System.Windows.Forms.MenuItem();
this.temperatureUnitsMenuItem = new System.Windows.Forms.MenuItem(); this.temperatureUnitsMenuItem = new System.Windows.Forms.MenuItem();
@ -302,6 +303,7 @@ namespace OpenHardwareMonitor.GUI {
this.optionsMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.optionsMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.startMinMenuItem, this.startMinMenuItem,
this.minTrayMenuItem, this.minTrayMenuItem,
this.minCloseMenuItem,
this.startupMenuItem, this.startupMenuItem,
this.separatorMenuItem, this.separatorMenuItem,
this.temperatureUnitsMenuItem, this.temperatureUnitsMenuItem,
@ -319,19 +321,24 @@ namespace OpenHardwareMonitor.GUI {
this.minTrayMenuItem.Index = 1; this.minTrayMenuItem.Index = 1;
this.minTrayMenuItem.Text = "Minimize To Tray"; this.minTrayMenuItem.Text = "Minimize To Tray";
// //
// minCloseMenuItem
//
this.minCloseMenuItem.Index = 2;
this.minCloseMenuItem.Text = "Minimize On Close";
//
// startupMenuItem // startupMenuItem
// //
this.startupMenuItem.Index = 2; this.startupMenuItem.Index = 3;
this.startupMenuItem.Text = "Run On Windows Startup"; this.startupMenuItem.Text = "Run On Windows Startup";
// //
// separatorMenuItem // separatorMenuItem
// //
this.separatorMenuItem.Index = 3; this.separatorMenuItem.Index = 4;
this.separatorMenuItem.Text = "-"; this.separatorMenuItem.Text = "-";
// //
// temperatureUnitsMenuItem // temperatureUnitsMenuItem
// //
this.temperatureUnitsMenuItem.Index = 4; this.temperatureUnitsMenuItem.Index = 5;
this.temperatureUnitsMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.temperatureUnitsMenuItem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.celciusMenuItem, this.celciusMenuItem,
this.fahrenheitMenuItem}); this.fahrenheitMenuItem});
@ -351,12 +358,12 @@ namespace OpenHardwareMonitor.GUI {
// //
// MenuItem4 // MenuItem4
// //
this.MenuItem4.Index = 5; this.MenuItem4.Index = 6;
this.MenuItem4.Text = "-"; this.MenuItem4.Text = "-";
// //
// hddMenuItem // hddMenuItem
// //
this.hddMenuItem.Index = 6; this.hddMenuItem.Index = 7;
this.hddMenuItem.Text = "Read HDD sensors"; this.hddMenuItem.Text = "Read HDD sensors";
// //
// helpMenuItem // helpMenuItem
@ -513,6 +520,7 @@ namespace OpenHardwareMonitor.GUI {
private System.Windows.Forms.MenuItem resetMinMaxMenuItem; private System.Windows.Forms.MenuItem resetMinMaxMenuItem;
private System.Windows.Forms.MenuItem MenuItem3; private System.Windows.Forms.MenuItem MenuItem3;
private System.Windows.Forms.MenuItem gadgetMenuItem; private System.Windows.Forms.MenuItem gadgetMenuItem;
private System.Windows.Forms.MenuItem minCloseMenuItem;
} }
} }

View File

@ -71,6 +71,7 @@ namespace OpenHardwareMonitor.GUI {
private UserOption showMax; private UserOption showMax;
private UserOption startMinimized; private UserOption startMinimized;
private UserOption minimizeToTray; private UserOption minimizeToTray;
private UserOption minimizeOnClose;
private UserOption autoStart; private UserOption autoStart;
private UserOption readHddSensors; private UserOption readHddSensors;
private UserOption showGadget; private UserOption showGadget;
@ -80,14 +81,14 @@ namespace OpenHardwareMonitor.GUI {
this.settings = new PersistentSettings(); this.settings = new PersistentSettings();
this.settings.Load(Path.ChangeExtension( this.settings.Load(Path.ChangeExtension(
System.Windows.Forms.Application.ExecutablePath, ".config")); Application.ExecutablePath, ".config"));
this.unitManager = new UnitManager(settings); this.unitManager = new UnitManager(settings);
// set the DockStyle here, to avoid conflicts with the MainMenu // set the DockStyle here, to avoid conflicts with the MainMenu
this.splitContainer.Dock = DockStyle.Fill; this.splitContainer.Dock = DockStyle.Fill;
int p = (int)System.Environment.OSVersion.Platform; int p = (int)Environment.OSVersion.Platform;
if ((p == 4) || (p == 128)) { if ((p == 4) || (p == 128)) {
splitContainer.BorderStyle = BorderStyle.None; splitContainer.BorderStyle = BorderStyle.None;
splitContainer.Border3DStyle = Border3DStyle.Adjust; splitContainer.Border3DStyle = Border3DStyle.Adjust;
@ -196,6 +197,8 @@ namespace OpenHardwareMonitor.GUI {
systemTray.IsMainIconEnabled = minimizeToTray.Value; systemTray.IsMainIconEnabled = minimizeToTray.Value;
}; };
minimizeOnClose = new UserOption("minCloseMenuItem", false, minCloseMenuItem, settings);
autoStart = new UserOption(null, startupManager.Startup, startupMenuItem, settings); autoStart = new UserOption(null, startupManager.Startup, startupMenuItem, settings);
autoStart.Changed += delegate(object sender, EventArgs e) { autoStart.Changed += delegate(object sender, EventArgs e) {
try { try {
@ -447,9 +450,25 @@ namespace OpenHardwareMonitor.GUI {
protected override void WndProc(ref Message m) { protected override void WndProc(ref Message m) {
const int WM_SYSCOMMAND = 0x112; const int WM_SYSCOMMAND = 0x112;
const int SC_MINIMIZE = 0xF020; const int SC_MINIMIZE = 0xF020;
const int SC_CLOSE = 0xF060;
if (minimizeToTray.Value && if (minimizeToTray.Value &&
m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) { m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
SysTrayHideShow(); 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 { } else {
base.WndProc(ref m); base.WndProc(ref m);
} }