110,566
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 重载WndProc消息处理函数
/// </summary>
/// <param name="m">windows消息 </param>
protected override void WndProc(ref System.Windows.Forms.Message m)
{
try
{
switch(m.Msg)
{
//系统退出消息处理,WM_QUERYENDSESSION是询问程序是否需要关闭,
//要有相应的反回值,0不关闭程序;1关闭程序
case WM_QUERYENDSESSION:
m.Result = (IntPtr)WM_TRUE;
return;
//休眠事件处理
case WM_POWERBROADCAST :
if (m.WParam == (IntPtr)PBT_APMQUERYSUSPEND)
{
//系统即将休眠消息处理
try
{
this.BusManager.Close();
m.Result = (IntPtr)WM_TRUE;
}
catch
{
//捕捉异常,不做处理
}
}
break;
default:
break;
}
base.WndProc (ref m);
}
catch(Exception e)
{
MessageBox.Show(e.Message);
}
}
/// <summary> /// 重载WndProc消息处理函数 /// </summary> /// <param name="m">windows消息 </param> protected override void WndProc(ref System.Windows.Forms.Message m) { try { switch(m.Msg) { //系统退出消息处理,WM_QUERYENDSESSION是询问程序是否需要关闭, //要有相应的反回值,0不关闭程序;1关闭程序 case WM_QUERYENDSESSION: m.Result = (IntPtr)WM_TRUE; return; //休眠事件处理 case WM_POWERBROADCAST : if (m.WParam == (IntPtr)PBT_APMQUERYSUSPEND) { //系统即将休眠消息处理 try { this.BusManager.Close(); m.Result = (IntPtr)WM_TRUE; } catch { //捕捉异常,不做处理 } } break; default: break; } base.WndProc (ref m); } catch(Exception e) { MessageBox.Show(e.Message); } }