Search results for 'WM_QueryEndSession'. 1 post(s) found.

  1. 2007/09/19 Detecting and preventing Windows shut down
2007/09/19 08:23

Detecting and preventing Windows shut down


When Windows is about to Shut Down, it sends a WM_QueryEndSession to all open applications. To detect (and Prevent Shutdown) , we must define a message handler to this message. Put this definition on the private section of the main form:

procedure WMQueryEndSession(var Msg : TWMQueryEndSession) ; message WM_QueryEndSession;


Also, to prevent Windows shutting down put this method in the implementation section of the unit:

procedure TForm1.WMQueryEndSession(var Msg : TWMQueryEndSession) ;
begin
if MessageDlg('Close Windows ?',
              mtConfirmation,
              [mbYes,mbNo], 0) = mrNo then
  Msg.Result := 0
else
  Msg.Result := 1 ;
end;

To detect Windows Shutdown, we must trap the WM_EndSession message. Declare a message handling procedure in your main Form's Private section:

Procedure WMEndSession(var Msg : TWMEndSession) ; message WM_EndSession;

Also, add the following procedure to the implementation section of your Unit:

procedure TForm1.WMEndSession(var Msg : TWMEndSession) ;
begin
if Msg.EndSession = TRUE then
  ShowMessage('Windows is shutting down ' + #10#13
              + 'at ' + FormatDateTime('c', Now)) ;
  inherited;
end;
Trackback 3 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 00:38 delete

    moneyideas

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 09:11 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:40 delete

    moneyideas