如何知道用戶執行的操作,即關機,重啓,待機,鎖定或註銷。我用下面的代碼來檢查,但我想識別每個案件和執行行動accordingly.please提出了一些方法來知道在Windows窗體應用程序如何確定系統是關閉/重新啓動還是用戶從WinForms應用程序註銷?
private static int WM_QUERYENDSESSION = 0x11;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
MessageBox.Show(m.Msg.ToString() + " Endsession: this is a logoff, shutdown, or reboot");
systemShutdown = true;
}
// If this is WM_QUERYENDSESSION, the closing event should be
// raised in the base WndProc.
base.WndProc(ref m);
}
灰色:所以我就不能確定其關閉或重新啓動此檢查method.will的LPARAM,感謝您的信息 – deepu 2011-03-09 06:44:09
@deepu:不,Windows不會停產區分和重新啓動。 Fun Mun Pieng提出的方法也沒有作出這樣的區分。您的唯一選項由['SessionEndReasons'枚舉](http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendreasons.aspx)作爲「註銷」和「SystemShutdown」給出。除了處理'WM_QUERYENDSESSION',你不會獲得更多的信息。 – 2011-03-09 06:56:04