示例#1
0
        public SubGroupNode(Guid schemeGuid, Guid subGroupGuid, PersistentSettings settings)
        {
            this.settings = settings;
            this.schemeGuid = schemeGuid;
            this.subGroup = new SettingSubGroup();
            this.subGroup.Guid = subGroupGuid.ToString();

            IntPtr friendlyName = Marshal.AllocHGlobal(1000);
            IntPtr powerSchemeGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Guid)));
            IntPtr groupGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Guid)));
            uint bufferSize = 1000;

            try
            {
                Marshal.StructureToPtr(schemeGuid, powerSchemeGuidPtr, true);
                Marshal.StructureToPtr(subGroupGuid, groupGuidPtr, true);

                //Pass the guid retrieved in PowerEnumerate as
                //parameter to get the sub group name.
                NativeMethods.PowerReadFriendlyName(IntPtr.Zero,
                    powerSchemeGuidPtr, groupGuidPtr, IntPtr.Zero, friendlyName, ref bufferSize);

                string subGroupName = Marshal.PtrToStringUni(friendlyName);
                this.subGroup.Name = subGroupName;

                this.subGroup.Description = PowerManager.GetDescription(schemeGuid.ToString(), subGroup.Guid, null);

            }
            finally
            {
                Marshal.FreeHGlobal(powerSchemeGuidPtr);
                Marshal.FreeHGlobal(groupGuidPtr);
                Marshal.FreeHGlobal(friendlyName);
            }
        }
        public SensorNode(ISensor sensor, PersistentSettings settings, 
            UnitManager unitManager)
            : base()
        {
            this.sensor = sensor;
              this.settings = settings;
              this.unitManager = unitManager;
              switch (sensor.SensorType) {
            case SensorType.Voltage: format = "{0:F3} V"; break;
            case SensorType.Clock: format = "{0:F0} MHz"; break;
            case SensorType.Load: format = "{0:F1} %"; break;
            case SensorType.Temperature: format = "{0:F1} °C"; break;
            case SensorType.Fan: format = "{0:F0} RPM"; break;
            case SensorType.Flow: format = "{0:F0} L/h"; break;
            case SensorType.Control: format = "{0:F1} %"; break;
            case SensorType.Level: format = "{0:F1} %"; break;
            case SensorType.Power: format = "{0:F1} W"; break;
            case SensorType.Data: format = "{0:F1} GB"; break;
            case SensorType.Factor: format = "{0:F3}"; break;
            case SensorType.DataRate: format = "{0:bf}/s"; break;
              }

              bool hidden = settings.GetValue(new Identifier(sensor.Identifier,
            "hidden").ToString(), sensor.IsDefaultHidden);
              base.IsVisible = !hidden;

              this.Plot = settings.GetValue(new Identifier(sensor.Identifier,
            "plot").ToString(), false);
        }
示例#3
0
        public PlotPanel(PersistentSettings settings)
        {
            this.settings = settings;

              this.SetStyle(ControlStyles.DoubleBuffer |
            ControlStyles.UserPaint |
            ControlStyles.AllPaintingInWmPaint |
            ControlStyles.ResizeRedraw, true);
              this.UpdateStyles();

              CreateContextMenu();

              centerlower = new StringFormat();
              centerlower.Alignment = StringAlignment.Center;
              centerlower.LineAlignment = StringAlignment.Near;

              centerleft = new StringFormat();
              centerleft.Alignment = StringAlignment.Far;
              centerleft.LineAlignment = StringAlignment.Center;

              lowerleft = new StringFormat();
              lowerleft.Alignment = StringAlignment.Far;
              lowerleft.LineAlignment = StringAlignment.Near;

              lightBrush = new SolidBrush(Color.FromArgb(245, 245, 245));
              lightPen = new Pen(Color.FromArgb(200, 200, 200));
        }
示例#4
0
    public UserOption(string name, bool value,
      MenuItem menuItem, PersistentSettings settings) {

      this.settings = settings;
      this.name = name;
      if (name != null)
        this.value = settings.GetValue(name, value);
      else
        this.value = value;
      this.menuItem = menuItem;
      this.menuItem.Checked = this.value;
      this.menuItem.Click += new EventHandler(menuItem_Click);
    }
    public HardwareNode(IHardware hardware, PersistentSettings settings, 
      UnitManager unitManager) : base() 
    {
      this.settings = settings;
      this.unitManager = unitManager;
      this.hardware = hardware;
      this.Image = HardwareTypeImage.Instance.GetImage(hardware.HardwareType);

      foreach (SensorType sensorType in Enum.GetValues(typeof(SensorType)))
        typeNodes.Add(new TypeNode(sensorType));

      foreach (ISensor sensor in hardware.Sensors)
        SensorAdded(sensor);

      hardware.SensorAdded +=new SensorEventHandler(SensorAdded);
      hardware.SensorRemoved += new SensorEventHandler(SensorRemoved);
    }
    public PlotPanel(PersistentSettings settings, UnitManager unitManager) {
      this.settings = settings;
      this.unitManager = unitManager;

      this.model = CreatePlotModel();

      this.plot = new Plot();
      this.plot.Dock = DockStyle.Fill;
      this.plot.Model = model;
      this.plot.BackColor = Color.White;
      this.plot.ContextMenu = CreateMenu();

      UpdateAxesPosition();

      this.SuspendLayout();
      this.Controls.Add(plot);
      this.ResumeLayout(true);
    }
    public UserRadioGroup(string name, int value,
      MenuItem[] menuItems, PersistentSettings settings) {
      this.settings = settings;
      this.name = name;
      if (name != null)
        this.value = settings.GetValue(name, value);
      else
        this.value = value;
      this.menuItems = menuItems;
      this.value = Math.Max(Math.Min(this.value, menuItems.Length - 1), 0);

      for (int i = 0; i < this.menuItems.Length; i++) {
        this.menuItems[i].Checked = i == this.value;
        int index = i;
        this.menuItems[i].Click += delegate(object sender, EventArgs e) {
          this.Value = index;
        };
      }      
    }
示例#8
0
        public SchemeNode(Guid schemeGuid, PersistentSettings settings)
            : base()
        {
            this.settings = settings;
            this.powerScheme = new PowerScheme();
            this.powerScheme.Guid = schemeGuid.ToString();

            IntPtr ptrToPowerSchemeGuid = IntPtr.Zero;
            IntPtr friendlyName = IntPtr.Zero;
            uint buffSize = 1000;

            try
            {
                friendlyName = Marshal.AllocHGlobal((int)buffSize);
                ptrToPowerSchemeGuid = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Guid)));
                Marshal.StructureToPtr(schemeGuid, ptrToPowerSchemeGuid, true);

                //Pass the guid retrieved in PowerEnumerate as parameter
                //to get the power scheme name.
                NativeMethods.PowerReadFriendlyName(
                    IntPtr.Zero, ptrToPowerSchemeGuid, IntPtr.Zero, IntPtr.Zero,
                    friendlyName, ref buffSize);

                this.powerScheme.Name = Marshal.PtrToStringUni(friendlyName);

                this.powerScheme.Description = PowerManager.GetDescription(powerScheme.Guid, null, null);
            }
            catch (Exception exception)
            {
                throw new PowerManagerException(exception.Message, exception);
            }
            finally
            {
                Marshal.FreeHGlobal(ptrToPowerSchemeGuid);
                Marshal.FreeHGlobal(friendlyName);
            }
        }
        public MainForm()
        {
            InitializeComponent();

              // check if the OpenHardwareMonitorLib assembly has the correct version
              if (Assembly.GetAssembly(typeof(Computer)).GetName().Version !=
            Assembly.GetExecutingAssembly().GetName().Version) {
            MessageBox.Show(
              "The version of the file OpenHardwareMonitorLib.dll is incompatible.",
              "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            Environment.Exit(0);
              }

              this.settings = new PersistentSettings();
              this.settings.Load(Path.ChangeExtension(
            Application.ExecutablePath, ".config"));

              this.unitManager = new UnitManager(settings);

              // make sure the buffers used for double buffering are not disposed
              // after each draw call
              BufferedGraphicsManager.Current.MaximumBuffer =
            Screen.PrimaryScreen.Bounds.Size;

              // set the DockStyle here, to avoid conflicts with the MainMenu
              this.splitContainer.Dock = DockStyle.Fill;

              this.Font = SystemFonts.MessageBoxFont;
              treeView.Font = SystemFonts.MessageBoxFont;

              plotPanel = new PlotPanel(settings, unitManager);
              plotPanel.Font = SystemFonts.MessageBoxFont;
              plotPanel.Dock = DockStyle.Fill;

              nodeCheckBox.IsVisibleValueNeeded += nodeCheckBox_IsVisibleValueNeeded;
              nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
              nodeTextBoxValue.DrawText += nodeTextBoxText_DrawText;
              nodeTextBoxMin.DrawText += nodeTextBoxText_DrawText;
              nodeTextBoxMax.DrawText += nodeTextBoxText_DrawText;
              nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;

              foreach (TreeColumn column in treeView.Columns)
            column.Width = Math.Max(20, Math.Min(400,
              settings.GetValue("treeView.Columns." + column.Header + ".Width",
              column.Width)));

              treeModel = new TreeModel();
              root = new Node(System.Environment.MachineName);
              root.Image = Utilities.EmbeddedResources.GetImage("computer.png");

              treeModel.Nodes.Add(root);
              treeView.Model = treeModel;

              this.computer = new Computer(settings);

              systemTray = new SystemTray(computer, settings, unitManager);
              systemTray.HideShowCommand += hideShowClick;
              systemTray.ExitCommand += exitClick;

              int p = (int)Environment.OSVersion.Platform;
              if ((p == 4) || (p == 128)) { // Unix
            treeView.RowHeight = Math.Max(treeView.RowHeight, 18);
            splitContainer.BorderStyle = BorderStyle.None;
            splitContainer.Border3DStyle = Border3DStyle.Adjust;
            splitContainer.SplitterWidth = 4;
            treeView.BorderStyle = BorderStyle.Fixed3D;
            plotPanel.BorderStyle = BorderStyle.Fixed3D;
            gadgetMenuItem.Visible = false;
            minCloseMenuItem.Visible = false;
            minTrayMenuItem.Visible = false;
            startMinMenuItem.Visible = false;
              } else { // Windows
            treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18);

            gadget = new SensorGadget(computer, settings, unitManager);
            gadget.HideShowCommand += hideShowClick;

            wmiProvider = new WmiProvider(computer);
              }

              logger = new Logger(computer);

              plotColorPalette = new Color[13];
              plotColorPalette[0] = Color.Blue;
              plotColorPalette[1] = Color.OrangeRed;
              plotColorPalette[2] = Color.Green;
              plotColorPalette[3] = Color.LightSeaGreen;
              plotColorPalette[4] = Color.Goldenrod;
              plotColorPalette[5] = Color.DarkViolet;
              plotColorPalette[6] = Color.YellowGreen;
              plotColorPalette[7] = Color.SaddleBrown;
              plotColorPalette[8] = Color.RoyalBlue;
              plotColorPalette[9] = Color.DeepPink;
              plotColorPalette[10] = Color.MediumSeaGreen;
              plotColorPalette[11] = Color.Olive;
              plotColorPalette[12] = Color.Firebrick;

              computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
              computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);

              computer.Open();

              timer.Enabled = true;

              showHiddenSensors = new UserOption("hiddenMenuItem", false,
            hiddenMenuItem, settings);
              showHiddenSensors.Changed += delegate(object sender, EventArgs e) {
            treeModel.ForceVisible = showHiddenSensors.Value;
              };

              showValue = new UserOption("valueMenuItem", true, valueMenuItem,
            settings);
              showValue.Changed += delegate(object sender, EventArgs e) {
            treeView.Columns[1].IsVisible = showValue.Value;
              };

              showMin = new UserOption("minMenuItem", false, minMenuItem, settings);
              showMin.Changed += delegate(object sender, EventArgs e) {
            treeView.Columns[2].IsVisible = showMin.Value;
              };

              showMax = new UserOption("maxMenuItem", true, maxMenuItem, settings);
              showMax.Changed += delegate(object sender, EventArgs e) {
            treeView.Columns[3].IsVisible = showMax.Value;
              };

              startMinimized = new UserOption("startMinMenuItem", false,
            startMinMenuItem, settings);

              minimizeToTray = new UserOption("minTrayMenuItem", true,
            minTrayMenuItem, settings);
              minimizeToTray.Changed += delegate(object sender, EventArgs e) {
            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 {
              startupManager.Startup = autoStart.Value;
            } catch (InvalidOperationException) {
              MessageBox.Show("Updating the auto-startup option failed.", "Error",
            MessageBoxButtons.OK, MessageBoxIcon.Error);
              autoStart.Value = startupManager.Startup;
            }
              };

              readMainboardSensors = new UserOption("mainboardMenuItem", true,
            mainboardMenuItem, settings);
              readMainboardSensors.Changed += delegate(object sender, EventArgs e) {
            computer.MainboardEnabled = readMainboardSensors.Value;
              };

              readCpuSensors = new UserOption("cpuMenuItem", true,
            cpuMenuItem, settings);
              readCpuSensors.Changed += delegate(object sender, EventArgs e) {
            computer.CPUEnabled = readCpuSensors.Value;
              };

              readRamSensors = new UserOption("ramMenuItem", true,
            ramMenuItem, settings);
              readRamSensors.Changed += delegate(object sender, EventArgs e) {
            computer.RAMEnabled = readRamSensors.Value;
              };

              readGpuSensors = new UserOption("gpuMenuItem", true,
            gpuMenuItem, settings);
              readGpuSensors.Changed += delegate(object sender, EventArgs e) {
            computer.GPUEnabled = readGpuSensors.Value;
              };

              readFanControllersSensors = new UserOption("fanControllerMenuItem", true,
            fanControllerMenuItem, settings);
              readFanControllersSensors.Changed += delegate(object sender, EventArgs e) {
            computer.FanControllerEnabled = readFanControllersSensors.Value;
              };

              readHddSensors = new UserOption("hddMenuItem", true, hddMenuItem,
            settings);
              readHddSensors.Changed += delegate(object sender, EventArgs e) {
            computer.HDDEnabled = readHddSensors.Value;
              };

              showGadget = new UserOption("gadgetMenuItem", false, gadgetMenuItem,
            settings);
              showGadget.Changed += delegate(object sender, EventArgs e) {
            if (gadget != null)
              gadget.Visible = showGadget.Value;
              };

              celsiusMenuItem.Checked =
            unitManager.TemperatureUnit == TemperatureUnit.Celsius;
              fahrenheitMenuItem.Checked = !celsiusMenuItem.Checked;

              server = new HttpServer(root, this.settings.GetValue("listenerPort", 8085));
              if (server.PlatformNotSupported) {
            webMenuItemSeparator.Visible = false;
            webMenuItem.Visible = false;
              }

              runWebServer = new UserOption("runWebServerMenuItem", false,
            runWebServerMenuItem, settings);
              runWebServer.Changed += delegate(object sender, EventArgs e) {
            if (runWebServer.Value)
              server.StartHTTPListener();
            else
              server.StopHTTPListener();
              };

              logSensors = new UserOption("logSensorsMenuItem", false, logSensorsMenuItem,
            settings);

              loggingInterval = new UserRadioGroup("loggingInterval", 0,
            new[] { log1sMenuItem, log2sMenuItem, log5sMenuItem, log10sMenuItem,
            log30sMenuItem, log1minMenuItem, log2minMenuItem, log5minMenuItem,
            log10minMenuItem, log30minMenuItem, log1hMenuItem, log2hMenuItem,
            log6hMenuItem},
            settings);
              loggingInterval.Changed += (sender, e) => {
            switch (loggingInterval.Value) {
              case 0: logger.LoggingInterval = new TimeSpan(0, 0, 1); break;
              case 1: logger.LoggingInterval = new TimeSpan(0, 0, 2); break;
              case 2: logger.LoggingInterval = new TimeSpan(0, 0, 5); break;
              case 3: logger.LoggingInterval = new TimeSpan(0, 0, 10); break;
              case 4: logger.LoggingInterval = new TimeSpan(0, 0, 30); break;
              case 5: logger.LoggingInterval = new TimeSpan(0, 1, 0); break;
              case 6: logger.LoggingInterval = new TimeSpan(0, 2, 0); break;
              case 7: logger.LoggingInterval = new TimeSpan(0, 5, 0); break;
              case 8: logger.LoggingInterval = new TimeSpan(0, 10, 0); break;
              case 9: logger.LoggingInterval = new TimeSpan(0, 30, 0); break;
              case 10: logger.LoggingInterval = new TimeSpan(1, 0, 0); break;
              case 11: logger.LoggingInterval = new TimeSpan(2, 0, 0); break;
              case 12: logger.LoggingInterval = new TimeSpan(6, 0, 0); break;
            }
              };

              InitializePlotForm();

              startupMenuItem.Visible = startupManager.IsAvailable;

              if (startMinMenuItem.Checked) {
            if (!minTrayMenuItem.Checked) {
              WindowState = FormWindowState.Minimized;
              Show();
            }
              } else {
            Show();
              }

              // Create a handle, otherwise calling Close() does not fire FormClosed
              IntPtr handle = Handle;

              // Make sure the settings are saved when the user logs off
              Microsoft.Win32.SystemEvents.SessionEnded += delegate {
            computer.Close();
            SaveConfiguration();
            if (runWebServer.Value)
              server.Quit();
              };
        }
 public UnitManager(PersistentSettings settings)
 {
     this.settings = settings;
       this.temperatureUnit = (TemperatureUnit)settings.GetValue("TemperatureUnit",
     (int)TemperatureUnit.Celsius);
 }
        public SensorNotifyIcon(SystemTray sensorSystemTray, ISensor sensor,
            bool balloonTip, PersistentSettings settings)
        {
            this.sensor = sensor;
              this.notifyIcon = new NotifyIcon();

              Color defaultColor = Color.Black;
              if (sensor.SensorType == SensorType.Load ||
              sensor.SensorType == SensorType.Control ||
              sensor.SensorType == SensorType.Level)
              {
            defaultColor = Color.FromArgb(0xff, 0x70, 0x8c, 0xf1);
              }
              Color = settings.GetValue(new Identifier(sensor.Identifier,
            "traycolor").ToString(), defaultColor);

              this.pen = new Pen(Color.FromArgb(96, Color.Black));
              this.font = SystemFonts.MessageBoxFont;

              ContextMenu contextMenu = new ContextMenu();
              MenuItem hideShowItem = new MenuItem("Hide/Show");
              hideShowItem.Click += delegate(object obj, EventArgs args) {
            sensorSystemTray.SendHideShowCommand();
              };
              contextMenu.MenuItems.Add(hideShowItem);
              contextMenu.MenuItems.Add(new MenuItem("-"));
              MenuItem removeItem = new MenuItem("Remove Sensor");
              removeItem.Click += delegate(object obj, EventArgs args) {
            sensorSystemTray.Remove(this.sensor);
              };
              contextMenu.MenuItems.Add(removeItem);
              MenuItem colorItem = new MenuItem("Change Color...");
              colorItem.Click += delegate(object obj, EventArgs args) {
            ColorDialog dialog = new ColorDialog();
            dialog.Color = Color;
            if (dialog.ShowDialog() == DialogResult.OK) {
              Color = dialog.Color;
              settings.SetValue(new Identifier(sensor.Identifier,
            "traycolor").ToString(), Color);
            }
              };
              contextMenu.MenuItems.Add(colorItem);
              contextMenu.MenuItems.Add(new MenuItem("-"));
              MenuItem exitItem = new MenuItem("Exit");
              exitItem.Click += delegate(object obj, EventArgs args) {
            sensorSystemTray.SendExitCommand();
              };
              contextMenu.MenuItems.Add(exitItem);
              this.notifyIcon.ContextMenu = contextMenu;
              this.notifyIcon.DoubleClick += delegate(object obj, EventArgs args) {
            sensorSystemTray.SendHideShowCommand();
              };

              // get the default dpi to create an icon with the correct size
              float dpiX, dpiY;
              using (Bitmap b = new Bitmap(1, 1, PixelFormat.Format32bppArgb)) {
            dpiX = b.HorizontalResolution;
            dpiY = b.VerticalResolution;
              }

              // adjust the size of the icon to current dpi (default is 16x16 at 96 dpi)
              int width = (int)Math.Round(16 * dpiX / 96);
              int height = (int)Math.Round(16 * dpiY / 96);

              // make sure it does never get smaller than 16x16
              width = width < 16 ? 16: width;
              height = height < 16 ? 16: height;

              this.bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
              this.graphics = Graphics.FromImage(this.bitmap);

              if (Environment.OSVersion.Version.Major > 5) {
            this.graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            this.graphics.SmoothingMode = SmoothingMode.HighQuality;
              }
        }
示例#12
0
        public MainForm()
        {
            InitializeComponent();

            this.settings = new PersistentSettings();
            this.settings.Load(Path.ChangeExtension(Application.ExecutablePath, ".config"));

            // make sure the buffers used for double buffering are not disposed
            // after each draw call
            BufferedGraphicsManager.Current.MaximumBuffer = Screen.PrimaryScreen.Bounds.Size;

            // set the DockStyle here, to avoid conflicts with the MainMenu
            this.splitContainer.Dock = DockStyle.Fill;

            this.Font = SystemFonts.MessageBoxFont;
            treeView.Font = SystemFonts.MessageBoxFont;

            nodeTextBoxText.DrawText += nodeTextBoxText_DrawText;
            nodeTextBoxACValue.DrawText += nodeTextBoxText_DrawText;
            nodeTextBoxDCValue.DrawText += nodeTextBoxText_DrawText;
            nodeTextBoxUnit.DrawText += nodeTextBoxText_DrawText;
            nodeTextBoxText.EditorShowing += nodeTextBoxText_EditorShowing;

            foreach (TreeColumn column in treeView.Columns)
            {
                column.Width = Math.Max(20, Math.Min(400,
                    settings.GetValue("treeView.Columns." + column.Header + ".Width",
                    column.Width)));
            }

            treeView.RowHeight = Math.Max(treeView.Font.Height + 1, 18);

            treeModel = new TreeModel();

            showHiddenSettings = new UserOption("hiddenMenuItem", false,
                hiddenMenuItem, settings);
            showHiddenSettings.Changed += delegate(object sender, EventArgs e)
            {
                treeModel.ForceVisible = showHiddenSettings.Value;
            };

            applyChanges = new UserOption("applyMenuItem", false,
                applyMenuItem, settings);

            forcePowerManager = new UserOption("forceMenuItem", false,
                forceMenuItem, settings);

            root = new ComputerNode(System.Environment.MachineName, settings);
            treeModel.Root = root;
            treeView.Model = treeModel;

            nodeTextBoxACValue.IsVisibleValueNeeded += nodeTextBoxAC_IsVisibleValueNeeded;
            nodeComboBoxACValue.IsVisibleValueNeeded += nodeComboBoxAC_IsVisibleValueNeeded;

            nodeComboBoxACValue.DrawText += nodeTextBoxText_DrawText;
            nodeTextBoxACValue.DataPropertyName = "AcValue";
            nodeComboBoxACValue.DataPropertyName = "AcValue";

            nodeTextBoxDCValue.IsVisibleValueNeeded += nodeTextBoxAC_IsVisibleValueNeeded;
            nodeComboBoxDCValue.IsVisibleValueNeeded += nodeComboBoxAC_IsVisibleValueNeeded;

            nodeComboBoxDCValue.DrawText += nodeTextBoxText_DrawText;
            nodeTextBoxDCValue.DataPropertyName = "DcValue";
            nodeComboBoxDCValue.DataPropertyName = "DcValue";

            Show();

            // Create a handle, otherwise calling Close() does not fire FormClosed
            IntPtr handle = Handle;

            // Make sure the settings are saved when the user logs off
            Microsoft.Win32.SystemEvents.SessionEnded += delegate
            {
                SaveConfiguration();
            };
        }
示例#13
0
        public SettingNode(Guid powerSchemeGuid, Guid subGroupGuid, Guid powerSettingGuid, PersistentSettings settings)
            : base()
        {
            this.settings = settings;
            this.powerSchemeGuid = powerSchemeGuid;
            this.subGroupGuid = subGroupGuid;

            uint returnCode = 0;
            IntPtr friendlyName = IntPtr.Zero;
            IntPtr settingGuidPtr = IntPtr.Zero;
            IntPtr subGroupGuidPtr = IntPtr.Zero;
            IntPtr powerSchemeGuidPtr = IntPtr.Zero;
            try
            {
                friendlyName = Marshal.AllocHGlobal(1000);
                settingGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Guid)));
                subGroupGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Guid)));
                powerSchemeGuidPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Guid)));
                uint bufferSize = 1000;

                Marshal.StructureToPtr(powerSchemeGuid, powerSchemeGuidPtr, true);
                Marshal.StructureToPtr(subGroupGuid, subGroupGuidPtr, true);
                Marshal.StructureToPtr(powerSettingGuid, settingGuidPtr, true);

                //Get the power setting name.
                NativeMethods.PowerReadFriendlyName(
                    IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, settingGuidPtr,
                    friendlyName, ref bufferSize);

                string settingName = Marshal.PtrToStringUni(friendlyName);

                powerSetting = new PowerSetting();
                powerSetting.Name = settingName;
                powerSetting.Guid = powerSettingGuid.ToString();
                powerSetting.Description = PowerManager.GetDescription(powerSchemeGuid.ToString(), subGroupGuid.ToString(), powerSetting.Guid);

                returnCode = NativeMethods.PowerReadACValueIndex(
                        IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, settingGuidPtr, ref acValue);

                returnCode = NativeMethods.PowerReadDCValueIndex(
                        IntPtr.Zero, powerSchemeGuidPtr, subGroupGuidPtr, settingGuidPtr, ref dcValue);

                isRange = NativeMethods.PowerIsSettingRangeDefined(subGroupGuidPtr, settingGuidPtr);

                // Bit mask !!!
                isHidden = 1 == (NativeMethods.PowerReadSettingAttributes(subGroupGuidPtr, settingGuidPtr) & 1);
                base.IsVisible = !isHidden;

                if ( isRange )
                {
                    ReadNonindexedValues(subGroupGuidPtr, settingGuidPtr);
                }
                else
                {
                    ReadIndexedValues(subGroupGuidPtr, settingGuidPtr);
                }
            }
            catch (Exception exception)
            {
                throw new PowerManagerException(exception.Message, exception);
            }
            finally
            {
                Marshal.FreeHGlobal(friendlyName);
                Marshal.FreeHGlobal(powerSchemeGuidPtr);
                Marshal.FreeHGlobal(subGroupGuidPtr);
                Marshal.FreeHGlobal(settingGuidPtr);
            }
        }
    public SystemTray(IComputer computer, PersistentSettings settings,
      UnitManager unitManager) 
    {
      this.computer = computer;
      this.settings = settings;
      this.unitManager = unitManager;
      computer.HardwareAdded += new HardwareEventHandler(HardwareAdded);
      computer.HardwareRemoved += new HardwareEventHandler(HardwareRemoved);

      this.mainIcon = new NotifyIconAdv();

      ContextMenu contextMenu = new ContextMenu();
      MenuItem hideShowItem = new MenuItem("Hide/Show");
      hideShowItem.Click += delegate(object obj, EventArgs args) {
        SendHideShowCommand();
      };
      contextMenu.MenuItems.Add(hideShowItem);
      contextMenu.MenuItems.Add(new MenuItem("-"));      
      MenuItem exitItem = new MenuItem("Exit");
      exitItem.Click += delegate(object obj, EventArgs args) {
        SendExitCommand();
      };
      contextMenu.MenuItems.Add(exitItem);
      this.mainIcon.ContextMenu = contextMenu;
      this.mainIcon.DoubleClick += delegate(object obj, EventArgs args) {
        SendHideShowCommand();
      };
      this.mainIcon.Icon = EmbeddedResources.GetIcon("smallicon.ico");
      this.mainIcon.Text = "Open Hardware Monitor";
    }