Trap ShutDown Event both on NT and Win9x


I want to trap event when my os is shutingdown both for win9x and nt

Esk
eskAsked:
Who is Participating?
 
daniel_cCommented:
Just write a message handler for WM_QUERYENDSESSION.

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. Windows stops sending WM_QUERYENDSESSION messages as soon as one application returns zero.

Example:

(this goes on the form's Private section):

  procedure WMQueryEndSession (var Message: TMessage); message WM_QUERYENDSESSION ;

Then simply write the code for the prototype above. The procedure will be called in the events described by the text above
0
 
eskAuthor Commented:
Explain better the procedure i add in my program msg := 1 or 0 ?

Esk
0
 
EpsylonCommented:
Esk, how about the other question? I'm still waiting for your response...
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
daniel_cCommented:
You do not need to seet msg to 1 or 0.
If user click, Start-Shutdown, then
WM_QUERYENDSESSION will be invoked.
So, just put your routines to the procedure WMQueryEndSession (var Message: TMessage); message WM_QUERYENDSESSION ;

Hope it will help,

Daniel

0
 
eskAuthor Commented:
does this work on my nt machine?
0
 
eskAuthor Commented:
Epsylon, how about NT?
0
 
EpsylonCommented:
Wow, I did not propose the answer. I only picked up your life sign here   :o)
0
 
eskAuthor Commented:
Alright , thanks but do you own asnwer for my question, you get 100 extra points + A

Esk
0
 
eskAuthor Commented:
Epsylon, i trust on you
0
 
EpsylonCommented:
I think this should be it:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMQueryEndSession (var Message: TMessage); message WM_QUERYENDSESSION ;
    procedure WMEndSession (var Message: TMessage); message WM_ENDSESSION ;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TForm1 }

procedure TForm1.WMQueryEndSession(var Message: TMessage);
begin
  if MessageDlg('WM_QUERYENDSESSION', mtConfirmation, mbOKCancel, 0) = mrOk then
    Message.Result := Integer(true)
  else
    Message.Result := Integer(false);
end;

procedure TForm1.WMEndSession(var Message: TMessage);
begin
  if BOOL(Message.WParam) = true then
    Close;
end;

end.
0
 
eskAuthor Commented:
won't work on my NT
0
 
eskAuthor Commented:
This work!!! sorry
0
 
eskAuthor Commented:
daniel_c, i gave you the points.  

i was trying to give Epsylon the points, his aswer was right

Esk
0
 
EpsylonCommented:
Hmmm......
0
 
eskAuthor Commented:
Is no way to take the points back?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.