WPF捕捉Windows关机事件
2020-12-13 03:29
标签:style class blog code http tar public XX{ } .NET技术交流群 199281001 .欢迎加入。 WPF捕捉Windows关机事件,搜素材,soscw.com WPF捕捉Windows关机事件 标签:style class blog code http tar 原文地址:http://www.cnblogs.com/gaobing/p/3809485.html1 private const int SC_SCREENSAVE = 0xF140;
2 private const int WM_QUERYENDSESSION = 0x0011;
3 private bool IsScreenSave = false;
4 private bool IsWindowStopClosing = false;
不废话,直接贴代码,构造函数中1 // 获得窗口句柄
2 IntPtr hwnd = new WindowInteropHelper(this).Handle;
3 // 在Win32窗口中显示WPF的内容
4 HwndSource src = HwndSource.FromHwnd(hwnd);
5 //接收窗口消息的处理程序实现(基于 System.Windows.Interop.HwndSourceHook 委托)
6 src.AddHook(new HwndSourceHook(WndProc));
1 ///