Changed minimizing to system tray on Windows systems.
3 Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 The contents of this file are subject to the Mozilla Public License Version
6 1.1 (the "License"); you may not use this file except in compliance with
7 the License. You may obtain a copy of the License at
9 http://www.mozilla.org/MPL/
11 Software distributed under the License is distributed on an "AS IS" basis,
12 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 for the specific language governing rights and limitations under the License.
15 The Original Code is the Open Hardware Monitor code.
17 The Initial Developer of the Original Code is
18 Michael Möller <m.moeller@gmx.ch>.
19 Portions created by the Initial Developer are Copyright (C) 2009-2010
20 the Initial Developer. All Rights Reserved.
24 Alternatively, the contents of this file may be used under the terms of
25 either the GNU General Public License Version 2 or later (the "GPL"), or
26 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 in which case the provisions of the GPL or the LGPL are applicable instead
28 of those above. If you wish to allow use of your version of this file only
29 under the terms of either the GPL or the LGPL, and not to allow others to
30 use your version of this file under the terms of the MPL, indicate your
31 decision by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL or the LGPL. If you do not delete
33 the provisions above, a recipient may use your version of this file under
34 the terms of any one of the MPL, the GPL or the LGPL.
39 using System.Collections.Generic;
40 using System.ComponentModel;
41 using System.Configuration;
44 using System.Windows.Forms;
45 using Aga.Controls.Tree;
46 using Aga.Controls.Tree.NodeControls;
47 using OpenHardwareMonitor.Hardware;
49 namespace OpenHardwareMonitor.GUI {
50 public partial class MainForm : Form {
53 private List<IGroup> groupList = new List<IGroup>();
54 private TreeModel treeModel;
55 private IDictionary<ISensor, Color> sensorPlotColors =
56 new Dictionary<ISensor, Color>();
57 private Color[] plotColorPalette;
61 InitializeComponent();
62 this.Font = SystemFonts.MessageBoxFont;
63 treeView.Font = SystemFonts.MessageBoxFont;
64 plotPanel.Font = SystemFonts.MessageBoxFont;
66 nodeCheckBox.IsVisibleValueNeeded +=
67 new EventHandler<NodeControlValueEventArgs>(
68 nodeCheckBox_IsVisibleValueNeeded);
69 nodeCheckBox.CheckStateChanged +=
70 new EventHandler<TreePathEventArgs>(UpdatePlotSelection);
71 nodeTextBoxText.DrawText +=
72 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
73 nodeTextBoxValue.DrawText +=
74 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
75 nodeTextBoxMin.DrawText +=
76 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
77 nodeTextBoxMax.DrawText +=
78 new EventHandler<DrawEventArgs>(nodeTextBoxText_DrawText);
79 nodeTextBoxLimit.DrawText +=
80 new EventHandler<DrawEventArgs>(nodeTextBoxLimit_DrawText);
82 if (Utilities.Config.Contains("mainForm.Location.X")) {
83 int x = Utilities.Config.Get("mainForm.Location.X", Location.X);
85 int y = Utilities.Config.Get("mainForm.Location.Y", Location.Y);
87 this.Location = new Point(x, y);
89 StartPosition = FormStartPosition.CenterScreen;
92 Width = Utilities.Config.Get("mainForm.Width", Width);
93 Height = Utilities.Config.Get("mainForm.Height", Height);
95 treeModel = new TreeModel();
96 root = new Node(System.Environment.MachineName);
97 root.Image = Utilities.EmbeddedResources.GetImage("computer.png");
99 treeModel.Nodes.Add(root);
100 treeView.Model = treeModel;
102 AddGroup(new Hardware.SMBIOS.SMBIOSGroup());
103 AddGroup(new Hardware.LPC.LPCGroup());
104 AddGroup(new Hardware.CPU.CPUGroup());
105 AddGroup(new Hardware.ATI.ATIGroup());
106 AddGroup(new Hardware.Nvidia.NvidiaGroup());
107 AddGroup(new Hardware.TBalancer.TBalancerGroup());
109 plotColorPalette = new Color[14];
110 plotColorPalette[0] = Color.Blue;
111 plotColorPalette[1] = Color.OrangeRed;
112 plotColorPalette[2] = Color.Green;
113 plotColorPalette[3] = Color.LightSeaGreen;
114 plotColorPalette[4] = Color.Goldenrod;
115 plotColorPalette[5] = Color.DarkViolet;
116 plotColorPalette[6] = Color.YellowGreen;
117 plotColorPalette[7] = Color.SaddleBrown;
118 plotColorPalette[8] = Color.Gray;
119 plotColorPalette[9] = Color.RoyalBlue;
120 plotColorPalette[10] = Color.DeepPink;
121 plotColorPalette[11] = Color.MediumSeaGreen;
122 plotColorPalette[12] = Color.Olive;
123 plotColorPalette[13] = Color.Firebrick;
125 plotMenuItem.Checked = Utilities.Config.Get(plotMenuItem.Name, false);
126 minMenuItem.Checked = Utilities.Config.Get(minMenuItem.Name, false);
127 maxMenuItem.Checked = Utilities.Config.Get(maxMenuItem.Name, true);
128 limitMenuItem.Checked = Utilities.Config.Get(limitMenuItem.Name, false);
129 hddMenuItem.Checked = Utilities.Config.Get(hddMenuItem.Name, true);
131 voltMenuItem.Checked = Utilities.Config.Get(voltMenuItem.Name, true);
132 clocksMenuItem.Checked = Utilities.Config.Get(clocksMenuItem.Name, true);
133 loadMenuItem.Checked = Utilities.Config.Get(loadMenuItem.Name, true);
134 tempMenuItem.Checked = Utilities.Config.Get(tempMenuItem.Name, true);
135 fansMenuItem.Checked = Utilities.Config.Get(fansMenuItem.Name, true);
137 timer.Enabled = true;
140 private void AddGroup(IGroup group) {
141 groupList.Add(group);
142 foreach (IHardware hardware in group.Hardware)
143 root.Nodes.Add(new HardwareNode(hardware));
146 private void RemoveGroup(IGroup group) {
147 List<Node> nodesToRemove = new List<Node>();
148 foreach (IHardware hardware in group.Hardware)
149 foreach (Node node in root.Nodes) {
150 HardwareNode hardwareNode = node as HardwareNode;
151 if (hardwareNode != null && hardwareNode.Hardware == hardware)
152 nodesToRemove.Add(node);
154 foreach (Node node in nodesToRemove)
155 root.Nodes.Remove(node);
156 groupList.Remove(group);
159 private void nodeTextBoxLimit_DrawText(object sender, DrawEventArgs e) {
160 SensorNode sensorNode = e.Node.Tag as SensorNode;
161 if (sensorNode != null)
162 e.Text = sensorNode.ValueToString(sensorNode.Sensor.Limit);
165 private void nodeTextBoxText_DrawText(object sender, DrawEventArgs e) {
166 if (!plotMenuItem.Checked)
169 SensorNode sensorNode = e.Node.Tag as SensorNode;
170 if (sensorNode != null) {
172 if (sensorPlotColors.TryGetValue(sensorNode.Sensor, out color))
177 private void UpdatePlotSelection(object sender,
180 List<ISensor> selected = new List<ISensor>();
181 IDictionary<ISensor, Color> colors = new Dictionary<ISensor, Color>();
183 foreach (TreeNodeAdv node in treeView.AllNodes) {
184 SensorNode sensorNode = node.Tag as SensorNode;
185 if (sensorNode != null &&
186 sensorNode.Sensor.SensorType == SensorType.Temperature) {
187 if (sensorNode.Plot) {
188 colors.Add(sensorNode.Sensor,
189 plotColorPalette[colorIndex % plotColorPalette.Length]);
190 selected.Add(sensorNode.Sensor);
195 sensorPlotColors = colors;
196 plotPanel.SetSensors(selected, colors);
199 private void nodeCheckBox_IsVisibleValueNeeded(object sender,
200 NodeControlValueEventArgs e) {
201 SensorNode node = e.Node.Tag as SensorNode;
202 e.Value = (node != null) &&
203 (node.Sensor.SensorType == SensorType.Temperature) &&
204 plotMenuItem.Checked;
207 private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
211 private void timer_Tick(object sender, EventArgs e) {
216 foreach (IGroup group in groupList)
217 foreach (IHardware hardware in group.Hardware)
220 } catch (Exception exception) {
221 Utilities.CrashReport.Save(exception);
226 treeView.Invalidate();
227 plotPanel.Invalidate();
230 private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {
231 Utilities.Config.Set(plotMenuItem.Name, plotMenuItem.Checked);
232 Utilities.Config.Set(minMenuItem.Name, minMenuItem.Checked);
233 Utilities.Config.Set(maxMenuItem.Name, maxMenuItem.Checked);
234 Utilities.Config.Set(limitMenuItem.Name, limitMenuItem.Checked);
235 Utilities.Config.Set(hddMenuItem.Name, hddMenuItem.Checked);
237 Utilities.Config.Set(voltMenuItem.Name, voltMenuItem.Checked);
238 Utilities.Config.Set(clocksMenuItem.Name, clocksMenuItem.Checked);
239 Utilities.Config.Set(loadMenuItem.Name, loadMenuItem.Checked);
240 Utilities.Config.Set(tempMenuItem.Name, tempMenuItem.Checked);
241 Utilities.Config.Set(fansMenuItem.Name, fansMenuItem.Checked);
243 if (WindowState != FormWindowState.Minimized) {
244 Utilities.Config.Set("mainForm.Location.X", Location.X);
245 Utilities.Config.Set("mainForm.Location.Y", Location.Y);
246 Utilities.Config.Set("mainForm.Width", Width);
247 Utilities.Config.Set("mainForm.Height", Height);
250 foreach (IGroup group in groupList)
254 private void aboutToolStripMenuItem_Click(object sender, EventArgs e) {
255 new AboutBox().ShowDialog();
258 private void plotToolStripMenuItem_CheckedChanged(object sender,
261 splitContainer.Panel2Collapsed = !plotMenuItem.Checked;
262 treeView.Invalidate();
265 private void valueToolStripMenuItem_CheckedChanged(object sender,
268 treeView.Columns[1].IsVisible = valueToolStripMenuItem.Checked;
271 private void minToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
273 treeView.Columns[2].IsVisible = minMenuItem.Checked;
276 private void maxToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
278 treeView.Columns[3].IsVisible = maxMenuItem.Checked;
281 private void limitToolStripMenuItem_CheckedChanged(object sender,
283 treeView.Columns[4].IsVisible = limitMenuItem.Checked;
286 private void treeView_Click(object sender, EventArgs e) {
288 MouseEventArgs m = e as MouseEventArgs;
289 if (m == null || m.Button != MouseButtons.Right)
292 NodeControlInfo info = treeView.GetNodeControlInfoAt(new Point(m.X, m.Y));
293 if (info.Control == null)
294 columnsContextMenuStrip.Show(treeView, m.X, m.Y);
297 private void saveReportToolStripMenuItem_Click(object sender, EventArgs e) {
298 ReportWriter.Save(groupList, new Version(Application.ProductVersion));
301 private void hddsensorsToolStripMenuItem_CheckedChanged(object sender,
304 if (hddMenuItem.Checked) {
305 AddGroup(new Hardware.HDD.HDDGroup());
306 UpdateSensorTypeChecked(null, null);
308 List<IGroup> groupsToRemove = new List<IGroup>();
309 foreach (IGroup group in groupList)
310 if (group is Hardware.HDD.HDDGroup)
311 groupsToRemove.Add(group);
312 foreach (IGroup group in groupsToRemove) {
316 UpdatePlotSelection(null, null);
320 private void UpdateSensorTypeChecked(object sender, EventArgs e) {
321 foreach (HardwareNode node in root.Nodes) {
322 node.SetVisible(SensorType.Voltage, voltMenuItem.Checked);
323 node.SetVisible(SensorType.Clock, clocksMenuItem.Checked);
324 node.SetVisible(SensorType.Load, loadMenuItem.Checked);
325 node.SetVisible(SensorType.Temperature, tempMenuItem.Checked);
326 node.SetVisible(SensorType.Fan, fansMenuItem.Checked);
330 private void ToggleSysTray() {
332 notifyIcon.Visible = true;
336 notifyIcon.Visible = false;
340 protected override void WndProc(ref Message m) {
341 const int WM_SYSCOMMAND = 0x112;
342 const int SC_MINIMIZE = 0xF020;
343 if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE) {
350 private void notifyIcon_Click(object sender, EventArgs e) {
351 MouseEventArgs m = e as MouseEventArgs;
352 if (m == null || m.Button != MouseButtons.Left)
358 private void restoreToolStripMenuItem_Click(object sender, EventArgs e) {