public bool WndProc(ref System.Windows.Forms.Message msg) { if ((msg.Msg == WindowsAPI.WM_SYSCOMMAND) && (msg.WParam.ToInt32() & 0xfff0) == WindowsAPI.SC_SCREENSAVE) { // there's no event for screensaver exit OnScreensaverActivated(true); } else if (msg.Msg == WindowsAPI.WM_POWERBROADCAST) { switch (msg.WParam.ToInt32()) { case WindowsAPI.PBT_APMSUSPEND: PowerStatusChanged?.Invoke(this, new SystemPowerChange(SystemPowerState.Standby)); return(true); case WindowsAPI.PBT_APMRESUMESUSPEND: case WindowsAPI.PBT_APMRESUMECRITICAL: case WindowsAPI.PBT_APMRESUMEAUTOMATIC: PowerStatusChanged?.Invoke(this, new SystemPowerChange(SystemPowerState.Wake)); return(true); case WindowsAPI.PBT_POWERSETTINGCHANGE: { WindowsAPI.POWERBROADCAST_SETTING pwr = (WindowsAPI.POWERBROADCAST_SETTING)Marshal.PtrToStructure(msg.LParam, typeof(WindowsAPI.POWERBROADCAST_SETTING)); if (pwr.PowerSetting == WindowsAPI.GUID_SYSTEM_AWAYMODE && pwr.DataLength == Marshal.SizeOf(typeof(Int32))) { switch (pwr.Data) { case 0: PowerStatusChanged?.Invoke(this, new SystemPowerChange(SystemPowerState.AwayExit)); return(true); case 1: PowerStatusChanged?.Invoke(this, new SystemPowerChange(SystemPowerState.AwayEnter)); return(true); default: break; } } } break; default: break; } } // pass up when not handled return(false); }
private void PowerModeChanged(object sender, PowerModeChangedEventArgs e) { if (e.Mode == PowerModes.Resume) { PowerStatusChanged?.Invoke(this, new PowerChangeStatusEventArgs(PowerChangeStatus.Resuming)); } else if (e.Mode == PowerModes.Suspend) { PowerStatusChanged?.Invoke(this, new PowerChangeStatusEventArgs(PowerChangeStatus.Suspending)); } else if (e.Mode == PowerModes.StatusChange) { PowerStatusChanged?.Invoke(this, new PowerChangeStatusEventArgs(PowerChangeStatus.StatusChanged)); } }
public void Toggle(string notes) { IsOn = !IsOn; PowerStatusChanged?.Invoke(this, new LightBulbPowerStatusChangedEventArgs(IsOn, notes)); }