using System.Windows;
using Microsoft.Win32;
namespace CatchHibernateMsg
{
/// <summary>
/// We will catch system's suspend and resume events by adding handlers in Microsoft.Win32.SystemEvents's static events.
/// So that when you suspend or resume your computer,it shall show a dialog to inform you.
/// </summary>
public partial class MainWindow : Window
{
SessionEndedEventHandler seeh;
PowerModeChangedEventHandler pmceh;
public MainWindow()
{
InitializeComponent();
addEventsHandlers();
}
private void addEventsHandlers()
{
this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing);
seeh = new SessionEndedEventHandler(SystemEvents_SessionEnded);
pmceh = new PowerModeChangedEventHandler(SystemEvents_PowerModeChanged);
SystemEvents.SessionEnded
WPF程序响应系统休眠唤醒消息
最新推荐文章于 2024-04-14 11:21:39 发布
本文介绍了如何在WPF应用程序中使用Microsoft.Win32.SystemEvents监听系统休眠和恢复事件。通过添加事件处理程序,当电脑进入休眠或唤醒状态时,程序会显示对话框通知用户。
摘要由CSDN通过智能技术生成