Solved

Trap ShutDown Event both on NT and Win9x

Posted on 2000-02-28
15
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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 this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 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