Solved

catching "windows shutdown"

Posted on 2001-09-07
6
188 Views
Last Modified: 2010-05-18
how do i make an application that triggers and event when a user tries to shutdown windows?
0
Comment
6 Comments
 
LVL 22

Expert Comment

by:mnasman
Comment Utility
windows send WM_QUERYENDSESSION message to the application running when it's trying to shutdown
0
 
LVL 22

Accepted Solution

by:
mnasman earned 200 total points
Comment Utility
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMQueryEndSession(var Msg : TWMQueryEndSession); message WM_QueryEndSession;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.WMQueryEndSession(var Msg : TWMQueryEndSession);
begin
  if MessageDlg('Close Windows ?', mtConfirmation, [mbYes,mbNo], 0) = mrNo then
    Msg.Result := 0
  else
    Msg.Result := 1;
end;


end.
0
 
LVL 2

Expert Comment

by:PeterLarsen
Comment Utility
There are two messages you should be aware of :
   procedure wmQueryEndSession(var msg:TMessage); message WM_QUERYENDSESSION;
and
   procedure WMENDSESSION(var msg:TMessage); message WM_ENDSESSION;

Regards
Peter
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Expert Comment

by:Dennis9
Comment Utility
Try this:

procedure TMainForm.FormCreate(Sender: TObject);
begin
Application.OnMessage := AppMessage;
end;

procedure TMainForm.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
Handled := False;
if Msg.message = WM_QUERYENDSESSION then
begin
Showmessage('Windows are about to close');
end;
Handled := false;//If u set it to true it will close
end;


Dennis
0
 
LVL 3

Expert Comment

by:karouri
Comment Utility
da best solutions in da universe have already been offered;)
0
 

Author Comment

by:dabestprogrammerindauniverse
Comment Utility
thanks everyone!!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 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

13 Experts available now in Live!

Get 1:1 Help Now