예제 #1
0
        /// <summary>
        /// Registers for power notifications.
        /// </summary>
        private static void RegisterForPowerNotifications()
        {
            if (!_listeningForPowerEvents)
            {
                _dummyMessageReceiver = new MessageSinkWindow();
                _windowHandle         = _dummyMessageReceiver.Handle;

                _handlePowerSource     = NativeMethods.RegisterPowerSettingNotification(_windowHandle, ref PowerSettings.GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE);
                _handleBatteryCapacity = NativeMethods.RegisterPowerSettingNotification(_windowHandle, ref PowerSettings.GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE);
                _handleMonitorOn       = NativeMethods.RegisterPowerSettingNotification(_windowHandle, ref PowerSettings.GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
                _handlePowerScheme     = NativeMethods.RegisterPowerSettingNotification(_windowHandle, ref PowerSettings.GUID_POWERSCHEME_PERSONALITY, DEVICE_NOTIFY_WINDOW_HANDLE);

                _listeningForPowerEvents = true;
            }
        }
예제 #2
0
        /// <summary>
        /// Registers for power notifications.
        /// </summary>
        private static void RegisterForPowerNotifications()
        {
            if (_listeningForPowerEvents) return;
            _dummyMessageReceiver = new MessageSinkWindow();
            _windowHandle = _dummyMessageReceiver.Handle;

            _handlePowerSource = NativeMethods.RegisterPowerSettingNotification(_windowHandle, ref PowerSettings.GUID_ACDC_POWER_SOURCE, DEVICE_NOTIFY_WINDOW_HANDLE);
            _handleBatteryCapacity = NativeMethods.RegisterPowerSettingNotification(_windowHandle, ref PowerSettings.GUID_BATTERY_PERCENTAGE_REMAINING, DEVICE_NOTIFY_WINDOW_HANDLE);
            _handleMonitorOn = NativeMethods.RegisterPowerSettingNotification(_windowHandle, ref PowerSettings.GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
            _handlePowerScheme = NativeMethods.RegisterPowerSettingNotification(_windowHandle, ref PowerSettings.GUID_POWERSCHEME_PERSONALITY, DEVICE_NOTIFY_WINDOW_HANDLE);

            _listeningForPowerEvents = true;
        }