private void Window_Closing(object sender, CancelEventArgs e) { if (Startup.IsShuttingDown) // show the windows desktop { Shell.ToggleDesktopIcons(true); } else if (altF4Pressed) // Show the Shutdown Confirmation Window { SystemPower.ShowShutdownConfirmation(); e.Cancel = true; } else // Eat it !!! { e.Cancel = true; } }
private void Window_Closing(object sender, CancelEventArgs e) { if (Startup.IsShuttingDown) // show the windows desktop { FullScreenHelper.Instance.FullScreenApps.CollectionChanged -= FullScreenApps_CollectionChanged; Shell.ToggleDesktopIcons(true); } else if (altF4Pressed) // Show the Shutdown Confirmation Window { SystemPower.ShowShutdownConfirmation(); e.Cancel = true; } else // Eat it !!! { e.Cancel = true; } }
private void Window_Closing(object sender, CancelEventArgs e) { if (altF4Pressed) // Show the Shutdown Confirmation Window { SystemPower.ShowShutdownConfirmation(); altF4Pressed = false; e.Cancel = true; } else if (!AllowClose) // Eat it !!! { e.Cancel = true; } if (!e.Cancel) { // unsubscribe from things Settings.Instance.PropertyChanged -= Settings_PropertyChanged; FullScreenHelper.Instance.FullScreenApps.CollectionChanged -= FullScreenApps_CollectionChanged; } }
private void OpenShutDownBox(object sender, RoutedEventArgs e) { SystemPower.ShowShutdownConfirmation(); }
private void OpenRebootBox(object sender, RoutedEventArgs e) { SystemPower.ShowRebootConfirmation(); }
private void OpenLogoffBox(object sender, RoutedEventArgs e) { SystemPower.ShowLogOffConfirmation(); }
/// <summary> /// Get Power Info /// </summary> /// <param name="pdatype"></param> /// <returns></returns> public static PowerInfo GetPowerInfo(PDAInfo.DevModel pdatype) { PowerInfo obj = null; try { int mRetLen; string temp_str; ushort temp; byte[] mBatVoltageBuf = new byte[2]; SystemPower.SYSTEM_POWER_STATUS_EX2 sSysPowerStatus = new SystemPower.SYSTEM_POWER_STATUS_EX2(); int wlen = Marshal.SizeOf(sSysPowerStatus); mRetLen = SystemPower.GetSystemPowerStatusEx2(ref sSysPowerStatus, wlen, true); if (mRetLen < 1) { return(null); // Get System Power Status Error } obj = new PowerInfo(); if (sSysPowerStatus.ACLineStatus == SystemPower.AC_LINE_ONLINE) { obj.PowerType = "AC power supply"; } else { obj.PowerType = "Battery power supply"; } { temp = (ushort)(((sSysPowerStatus.BatteryVoltage)) / 100); //2903 mBatVoltageBuf[0] = (byte)temp; //ProcessVoltageValue(temp); } mBatVoltageBuf[1] = (byte)(mBatVoltageBuf[0] % 10); mBatVoltageBuf[0] = (byte)(mBatVoltageBuf[0] / 10); temp_str = string.Format("{0}.{1}V", mBatVoltageBuf[0], mBatVoltageBuf[1]); obj.Voltage = temp_str; //lifePercent; temp = sSysPowerStatus.BatteryLifePercent; if ((temp >= 100) && (temp != SystemPower.BATTERY_PERCENTAGE_UNKNOWN)) { temp = 100; } if ((temp == SystemPower.BATTERY_PERCENTAGE_UNKNOWN) || (sSysPowerStatus.ACLineStatus == SystemPower.AC_LINE_ONLINE)) { obj.LifePercent = "Unknow"; } else { { mBatVoltageBuf[0] = (byte)temp; } temp_str = string.Format("{0} %", mBatVoltageBuf[0]); obj.LifePercent = temp_str; } temp = sSysPowerStatus.BatteryFlag; switch ((uint)temp) { case SystemPower.BATTERY_FLAG_HIGH: obj.BaterryStatus = "Discharge"; break; case SystemPower.BATTERY_FLAG_LOW: obj.BaterryStatus = "Power lower"; break; case SystemPower.BATTERY_FLAG_CRITICAL: obj.BaterryStatus = "Power extremely low"; break; case SystemPower.BATTERY_FLAG_CHARGING: obj.BaterryStatus = "Charging"; break; case SystemPower.BATTERY_FLAG_NO_BATTERY: obj.BaterryStatus = "No baterry"; break; case SystemPower.BATTERY_FLAG_UNKNOWN: default: obj.BaterryStatus = "Unknown status"; break; } //backup battery obj.BakcupBatteryFlag = sSysPowerStatus.BackupBatteryFlag; if (obj.BakcupBatteryFlag != SystemPower.BATTERY_FLAG_NO_BATTERY || obj.BakcupBatteryFlag != sSysPowerStatus.BackupBatteryFlag) { int bval = sSysPowerStatus.BackupBatteryVoltage; byte[] tmpBuf = new byte[2]; tmpBuf[0] = (byte)(bval / 100); tmpBuf[1] = (byte)(tmpBuf[0] / 10); tmpBuf[0] = (byte)(tmpBuf[0] % 10); obj.BakcupBatteryVoltage = Convert.ToSingle(string.Format("{0}.{1}", tmpBuf[1], tmpBuf[0])); int bPer = sSysPowerStatus.BackupBatteryLifePercent; if ((bPer > 100) && (bPer != SystemPower.BATTERY_PERCENTAGE_UNKNOWN)) { bPer = 100; } if (bPer == SystemPower.BATTERY_PERCENTAGE_UNKNOWN) { obj.BakcupBatteryLifePercent = 0; } else { obj.BakcupBatteryLifePercent = (byte)bPer; } } } catch { } return(obj); }