PeteMulford
asked on
What events are triggered during a 'logoff'
Hi
What events are triggered when a user logs off from windows 2000/xp etc?
I have tried a test using the events below, but none of them seem to get triggered.
Thanks
Pete
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
debugMSG ('formclose');
showmessage('formclose');
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
debugMSG ('formdestroy');
showmessage('formdestroy') ;
end;
procedure TForm1.WMENDSESSION(var Msg: TMessage);
begin
debugMSG ('wmendsession');
showmessage('wmendsession' );
end;
procedure TForm1.WMQUERYENDSESSION(v ar Msg: TMessage);
begin
debugMSG ('WMQUERYENDSESSION');
showmessage('WMQUERYENDSES SION');
end;
procedure TForm1.FormCloseQuery(Send er: TObject; var CanClose: Boolean);
begin
debugMSG ('FormCloseQuery');
end;
What events are triggered when a user logs off from windows 2000/xp etc?
I have tried a test using the events below, but none of them seem to get triggered.
Thanks
Pete
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
debugMSG ('formclose');
showmessage('formclose');
end;
procedure TForm1.FormDestroy(Sender:
begin
debugMSG ('formdestroy');
showmessage('formdestroy')
end;
procedure TForm1.WMENDSESSION(var Msg: TMessage);
begin
debugMSG ('wmendsession');
showmessage('wmendsession'
end;
procedure TForm1.WMQUERYENDSESSION(v
begin
debugMSG ('WMQUERYENDSESSION');
showmessage('WMQUERYENDSES
end;
procedure TForm1.FormCloseQuery(Send
begin
debugMSG ('FormCloseQuery');
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Tested on XP. it created the 'c:\closeEvents.txt' file with following content and did not log off
26/06/2006 1:40:32 PM:OnLogOff
26/06/2006 1:40:32 PM:OnLogOff
ASKER
Many thanks to both of you. Both solutions actually work, seemingly equally well, it was another application causing my problems by forcing a loggoff.
Pete
Pete
ASKER
Thank you, I tried your suggestion with a small demo project, but that event doesnt seem to get triggered either :( I'm testing it on a win 2000 client pc connected to a windows 2000 server based network. The pc I'm testing it on does not have the IDE installed. I also noticed that it 'logs off' very quickly, not sure if thats a network setting, but shall investigate.
My code is:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
procedure OnLogOff(var Msg : TMessage); message WM_QUERYENDSESSION;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure debugMSG(msg:string);
const
FileName = 'c:\closeEvents.txt';
var
F: TextFile;
begin
AssignFile(f,FileName);
if FileExists(FileName) then Append(f)
else
Rewrite(f);
try writeln(f,DateTimeToStr(No
except windows.Beep(200,50);
end;
// ShowMessage(DateTimeToStr(
CloseFile(f);
end;
procedure TForm1.OnLogOff(var Msg: TMessage);
begin
debugMSG ('OnLogOff');
ShowMessage('OnLogOff');
Msg.Result := 0; // This will stop the log off
end;
end.