Solved

Trap ShutDown Event both on NT and Win9x

Posted on 2000-02-28
15
258 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
 
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
TcomboBox uninverted item 3 44
Thread safe  opinion 7 111
PDF library for Delphi 2 89
Delphi IDE crash without error message ... 7 59
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now