Link to home
Start Free TrialLog in
Avatar of esk
esk

asked on

Trap ShutDown Event both on NT and Win9x


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

Esk
ASKER CERTIFIED SOLUTION
Avatar of daniel_c
daniel_c

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of esk
esk

ASKER

Explain better the procedure i add in my program msg := 1 or 0 ?

Esk
Esk, how about the other question? I'm still waiting for your response...
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

Avatar of esk

ASKER

does this work on my nt machine?
Avatar of esk

ASKER

Epsylon, how about NT?
Wow, I did not propose the answer. I only picked up your life sign here   :o)
Avatar of esk

ASKER

Alright , thanks but do you own asnwer for my question, you get 100 extra points + A

Esk
Avatar of esk

ASKER

Epsylon, i trust on you
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.
Avatar of esk

ASKER

won't work on my NT
Avatar of esk

ASKER

This work!!! sorry
Avatar of esk

ASKER

daniel_c, i gave you the points.  

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

Esk
Hmmm......
Avatar of esk

ASKER

Is no way to take the points back?