Beispiel #1
0
        public PowerBroadcasts(PowerSettingsNotification notifications, PowerEventProvider provider)
        {
            this.notificationHandles     = new Dictionary <PowerSettingsNotification, IntPtr>();
            this.provider                = provider;
            this.provider.EventReceived += provider_EventReceived;

            RegisterNotifications(notifications);
        }
Beispiel #2
0
 public void UnregisterNotifications(PowerSettingsNotification notifications)
 {
     foreach (PowerSettingsNotification n in notifications.GetFlags())
     {
         if (this.notificationHandles.ContainsKey(n))
         {
             NativeMethods.UnregisterPowerSettingNotification(this.notificationHandles[n]);
             this.notificationHandles.Remove(n);
         }
     }
 }
Beispiel #3
0
        public void RegisterNotifications(PowerSettingsNotification notifications)
        {
            foreach (PowerSettingsNotification n in notifications.GetFlags())
            {
                if (!this.notificationHandles.ContainsKey(n))
                {
                    Guid guid = Guid.Empty;

                    switch (n)
                    {
                    case PowerSettingsNotification.BatteryPercentage:
                        guid = NativeMethods.GUID_BATTERY_PERCENTAGE_REMAINING;
                        break;

                    case PowerSettingsNotification.LidswitchState:
                        guid = NativeMethods.GUID_LIDSWITCH_STATE_CHANGE;
                        break;

                    case PowerSettingsNotification.PowerSchemePersonality:
                        guid = NativeMethods.GUID_POWERSCHEME_PERSONALITY;
                        break;

                    case PowerSettingsNotification.PowerSource:
                        guid = NativeMethods.GUID_ACDC_POWER_SOURCE;
                        break;

                    case PowerSettingsNotification.DisplayState:
                        //if (Environment.OSVersion.Version >= NT62Version)
                        //{
                        //    guid = NativeMethods.GUID_CONSOLE_DISPLAY_STATE;
                        //}
                        //else
                    {
                        guid = NativeMethods.GUID_MONITOR_POWER_ON;
                    }
                    break;
                    }

                    IntPtr handle = NativeMethods.RegisterPowerSettingNotification(
                        this.provider.ReceiverHandle,
                        ref guid,
                        (int)this.provider.HandleType);

                    this.notificationHandles.Add(n, handle);
                }
            }
        }