Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Differentiate between a Windows shutdown and a user's close request Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
03-Dec-02
Category
System
Language
Delphi 2.x
Views
129
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Jonas Bilinkevicius

How can I differentiate between a Windows shutdown and a user's close request (Alt 
+ F4 / titlebar close icon / file menu + close item / etc.) so that I can bypass 
the OnCloseQuery logic during a shutdown?

Answer:

Windows sends a WM_QUERYENDSESSION message to the main window of your application. 
The default processing for that invokes your CloseQuery method, which (in your 
logged out case) replies "No". So you need to watch for the WM_QUERYENDSESSION 
message and set a flag for your CloseQuery method. Give the form a flag and method 
like so:
1   
2   FShuttingDown: Boolean;
3   
4   procedure WMQueryEndSession(var Msg: TMessage); message WM_QUERYENDSESSION;
5   
6   procedure TForm1.WMQueryEndSession(var Msg: TMessage);
7   begin
8     {Tell CloseQuery it's a shutdown operation}
9     FShuttingDown := True;
10    {Let the default stuff happen to see if we can otherwise close}
11    inherited;
12  end;


Then in your CloseQuery event handler do:
13  
14  if FShuttingDown then
15    CanClose := True
16  else
17    CanCLose := {User if "logged in"};


It is possible for the shutdown to be aborted by another application, however. So 
you need to watch for the WM_ENDSESSION message that gets sent telling you if you 
really are going to shut down:
18  
19  procedure WMEndSession(var Msg: TMessage); message WM_ENDSESSION;
20  
21  procedure TForm1.WMEndSession(var Msg: TMessage);
22  begin
23    {Clear the flag if the shutdown was aborted}
24    FShuttingDown := Msg.WParam <> 0;
25  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC