[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Trap ShutDown Event both on NT and Win9x

Posted on 2000-02-28
15
Medium Priority
?
266 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
Industry Leaders: 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

650 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