예제 #1
0
 protected void OnDisplayStateChanged(DisplayStateEventArgs args)
 {
     if (this.DisplayStateChanged != null)
     {
         DisplayStateChanged(this, args);
     }
 }
예제 #2
0
        void provider_EventReceived(object sender, PowerEventArgs e)
        {
            if (e.EventType == NativeMethods.PBT_POWERSETTINGCHANGE)
            {
                var powerSettings = (NativeMethods.POWERBROADCAST_SETTING)Marshal.PtrToStructure(
                    e.Data, typeof(NativeMethods.POWERBROADCAST_SETTING));

                if (powerSettings.PowerSetting == NativeMethods.GUID_ACDC_POWER_SOURCE)
                {
                    var args = new PowerLineStatusEventArgs()
                    {
                        PowerCondition = (SystemPowerCondition)powerSettings.Data
                    };

                    OnPowerLineStatusChanged(args);
                }
                else if (powerSettings.PowerSetting == NativeMethods.GUID_BATTERY_PERCENTAGE_REMAINING)
                {
                    var args = new BatteryStatusEventArgs()
                    {
                        BatteryPercentageRemaining = (int)powerSettings.Data
                    };

                    OnBatteryStatusChanged(args);
                }
                else if (powerSettings.PowerSetting == NativeMethods.GUID_LIDSWITCH_STATE_CHANGE)
                {
                    var args = new LidswitchStateEventArgs()
                    {
                        IsLidOpen = powerSettings.Data != 0
                    };

                    OnLidswitchStateChanged(args);
                }
                else if (powerSettings.PowerSetting == NativeMethods.GUID_POWERSCHEME_PERSONALITY)
                {
                    var args = new PowerSchemeEventArgs();

                    if (powerSettings.PowerSchemePersonality == NativeMethods.GUID_TYPICAL_POWER_SAVINGS)
                    {
                        args.Personality = PowerSchemePersonality.Automatic;
                    }
                    else if (powerSettings.PowerSchemePersonality == NativeMethods.GUID_MIN_POWER_SAVINGS)
                    {
                        args.Personality = PowerSchemePersonality.PowerSaver;
                    }
                    else if (powerSettings.PowerSchemePersonality == NativeMethods.GUID_MAX_POWER_SAVINGS)
                    {
                        args.Personality = PowerSchemePersonality.HighPerformance;
                    }

                    OnPowerSchemePersonalityChanged(args);
                }
                else if (powerSettings.PowerSetting == NativeMethods.GUID_MONITOR_POWER_ON ||
                         powerSettings.PowerSetting == NativeMethods.GUID_CONSOLE_DISPLAY_STATE)
                {
                    var args = new DisplayStateEventArgs()
                    {
                        DisplayState = (DisplayState)powerSettings.Data
                    };

                    OnDisplayStateChanged(args);
                }
            }
        }