Solved

Trap ShutDown Event both on NT and Win9x

Posted on 2000-02-28
15
262 Views
Last Modified: 2010-04-04

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

Esk
0
Comment
Question by:esk
  • 9
  • 4
  • 2
15 Comments
 
LVL 7

Accepted Solution

by:
daniel_c earned 100 total points
ID: 2565582
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
 

Author Comment

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

Esk
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2572596
Esk, how about the other question? I'm still waiting for your response...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 7

Expert Comment

by:daniel_c
ID: 2578647
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
 

Author Comment

by:esk
ID: 2582950
does this work on my nt machine?
0
 

Author Comment

by:esk
ID: 2585575
Epsylon, how about NT?
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2585608
Wow, I did not propose the answer. I only picked up your life sign here   :o)
0
 

Author Comment

by:esk
ID: 2585877
Alright , thanks but do you own asnwer for my question, you get 100 extra points + A

Esk
0
 

Author Comment

by:esk
ID: 2588498
Epsylon, i trust on you
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2589208
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
 

Author Comment

by:esk
ID: 2595298
won't work on my NT
0
 

Author Comment

by:esk
ID: 2595387
This work!!! sorry
0
 

Author Comment

by:esk
ID: 2595393
daniel_c, i gave you the points.  

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

Esk
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2596720
Hmmm......
0
 

Author Comment

by:esk
ID: 2599832
Is no way to take the points back?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create a path if not exists 7 89
how to resize animated Gif image in delphi ? 1 34
How to build JSON File in Delphi 6 3 45
scroll down TListBox component in Delphi 1 19
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question