Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Thread Tools Display Modes
Old 01-12-2001, 11:53 AM
osamaao osamaao is offline
Join Date: Jan 2001
Posts: 94
Default Detecting if windows is shutting down...

Hi :
how can I implement an event that triggers before the system shuts downs.

thank , Osama.
Reply With Quote
Old 01-12-2001, 12:07 PM
Lapince Lapince is offline
Senior Member
Join Date: Jan 2001
Posts: 163
Default RE: Detecting if windows is shutting down...


When user click on shutdown, Windows sends to all apps the WM_QUERYENDSESSION messages. After all applications agreed with shuting down, Windows sends WM_ENDSESSIONmessage.
If an app tries to shutdown with EWX_FORCE, then WM_QUERYENDSESSIONisn't sent.

Reply With Quote
Old 01-12-2001, 12:16 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
Join Date: Jan 2001
Posts: 7,260
Default RE: Detecting if windows is shutting down...

Some info...

Go to and download
my TSystemEvents component. It will let you know when Windows is shutting
down by firing an event.

Your main form will receive a WM_QUERYENDSESSION message when Windows
prepares to close. The default action for this message is to just fire
the forms OnCloseQuery event.

The WM_QUERYENDSESSION message is sent when the user chooses to end
the Windows session or when an application calls the ExitWindows
function. If any application returns zero, the Windows session is not

{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);
if MessageDlg('Close Windows ?',
[mbYes,mbNo], 0) = mrNo then
Msg.Result := 0
Msg.Result := 1;

{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);

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

procedure TForm1.WMEndSession
(var Msg : TWMEndSession);
if Msg.EndSession = TRUE then
ShowMessage('Windows is shutting down ' + #10#13
+ 'at ' + FormatDateTime('c', Now));
Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

All times are GMT. The time now is 02:00 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.