?
Solved

Trap ShutDown Event both on NT and Win9x

Posted on 2000-02-28
15
Medium Priority
?
265 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 400 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

801 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