标签:style class blog code http tar
1 private const int SC_SCREENSAVE = 0xF140; 2 private const int WM_QUERYENDSESSION = 0x0011; 3 private bool IsScreenSave = false; 4 private bool IsWindowStopClosing = false;
不废话,直接贴代码,构造函数中
public XX{
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 /// <summary> 2 /// 重新WndProc 3 /// </summary> 4 /// <param name="hwnd">窗口句柄</param> 5 /// <param name="msg">消息ID</param> 6 /// <param name="wParam">消息的 wParam 值</param> 7 /// <param name="lParam">消息的 lParam 值</param> 8 /// <param name="handled">指示该消息是否已处理的值。如果该消息已处理,请将值设置为 true;否则请将其设置为 false</param> 9 /// <returns></returns> 10 private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) 11 { 12 if (msg == WM_QUERYENDSESSION) 13 { 14 using (var wcf = new KeFuServicesClient()) 15 { 16 wcf.UpdateUserState(MainPanelWindow.ClientServiceID, UserStates.UnLine); 17 } 18 } 19 return IntPtr.Zero; 20 }
.NET技术交流群 199281001 .欢迎加入。
WPF捕捉Windows关机事件,布布扣,bubuko.com
标签:style class blog code http tar
原文地址:http://www.cnblogs.com/gaobing/p/3809485.html