日期:2014-05-17  浏览次数:20985 次

程序关不了机,Win7下可以,XP都不行
各种关机代码都试了:
1,
  protected override void WndProc(ref Message m)
        {
                switch (m.Msg)
                {
                    case 0x0011://WM_QUERYENDSESSION
                        bExitApp = true;
                        m.Result = (IntPtr)1;
                        break;
                    default:
                        base.WndProc(ref m);
                        break;
                }
        }
private void FrmMsgMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (bExitApp)
            {
               e.Cancel = false;
                this.Close();
            }
           else
           {
                e.Cancel = true;
                this.Hide();
           }
}

2,监控系统关机在处理也没用
SystemEvents.SessionEnding += new SessionEndingEventHandler(SystemEvents_SessionEnding);