110,565
社区成员
发帖
与我相关
我的任务
分享
const int WM_ENDSESSION = 0x0016;
const int WM_QUERYENDSESSION = 0x0011;
/// <summary>
/// 询问是否关机(false否关机,true是关机)
/// </summary>
bool bQueryExitApp = false;
#region 关机代码
/// <summary>
/// 操作系统关闭时,关闭应用程序
/// </summary>
/// <param name="m">截获系统消息</param>
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_QUERYENDSESSION://WM_QUERYENDSESSION
bQueryExitApp = true;
break;
case WM_ENDSESSION://WM_ENDSESSION 系统指示:关掉
{
bQueryExitApp = true;
this.notifyJasic.Visible = false;
this.notifyJasic.Dispose();
this.tmRefreshDBSX.Enabled = false;
this.tmRefreshDBSX.Dispose();
KillSendImageThread();
KillRefreshThread();
CloseAllOpenForm();
try
{
this.Close();
}
catch (Exception ex)
{
Environment.Exit(-1);
}
Application.Exit();
}
break;
default:
break;
}
base.WndProc(ref m);
}
private void FrmMsgMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (!bQueryExitApp)
{
e.Cancel = true;
this.Hide();
}
}