Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-12-2001, 11:53 AM
osamaao osamaao is offline
Member
 
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
  #2  
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...

Hi,

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.

Lapince
Reply With Quote
  #3  
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...

1:
Go to http://www.used-disks.com/delphi/Components/Default.htm and download
my TSystemEvents component. It will let you know when Windows is shutting
down by firing an event.

2.
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.

3.
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
ended.

4.
{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;
Reply With Quote
Reply

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 12:51 PM.


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