Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-07

Lazarus and Windows messages

6 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

ik

Hello,

It's the first time that I use Lazarus with Windows, and almost 10 years since I last developed to Windows.

I'm trying to capture the windows message WM_QUERYENDSESSION (that exists on JwaWinUser).

I did something like this:

TForm1 = class(TForm)
...
private

  procedure WMQueryEndSession(var Msg : TLMessage); message

WM_QUERYENDSESSION
...

end;
...
procedure TForm1.WMQueryEndSession(var Msg : TLMessage);
begin
  case Msg.lParam of
     ENDSESSION_CLOSEAPP : ShowMessage('Closing Application'); // Added it
by hand <-
http://msdn.microsoft.com/en-us/library/windows/desktop/aa376890%28v=vs.85%29.aspx
     ENDSESSION_CRITICAL : ShowMessage('Critical reason');
     ENDSESSION_LOGOFF : ShowMessage('Log off');
  end;
  Msg.Result := 1;
end;
...

It looks like the message never fires.

I'm using Windows 7 64 bit, Lazarus 0.9.30.4 FPC 2.6.0 i386

What am I missing or doing wrong ?

Thanks,
Ido
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120702/e872bd46/attachment.html>

Reply by email

Mattias Gaertner
to ik
Show quoted text 15 lines
Hello, It's the first time that I use Lazarus with Windows, and almost 10 years since I last developed to Windows. I'm trying to capture the windows message WM_QUERYENDSESSION (that exists on JwaWinUser). I did something like this: TForm1 = class(TForm) ... private procedure WMQueryEndSession(var Msg : TLMessage); message WM_QUERYENDSESSION

Why not simply drop a ApplicationProperties onto the form and set the OnQueryEndSession event?

Mattias

Reply by email

ik
to Mattias Gaertner

On Mon, Jul 2, 2012 at 10:16 PM, Mattias Gaertner <

Show quoted text 24 lines
wrote: On Mon, 2 Jul 2012 22:00:05 +0300 ik wrote: > Hello, > > It's the first time that I use Lazarus with Windows, and almost 10 years > since I last developed to Windows. > > I'm trying to capture the windows message WM_QUERYENDSESSION (that exists > on JwaWinUser). > > I did something like this: > > TForm1 = class(TForm) > ... > private > procedure WMQueryEndSession(var Msg : TLMessage); message > WM_QUERYENDSESSION Why not simply drop a ApplicationProperties onto the form and set the OnQueryEndSession event?

Because I must know when the log off, and do some tasks before I can end the program. I must know that the endsession request was made because of such request, and OnQueryEndSession does not contain such details as far as i can see.

Mattias

Ido

Show quoted text 7 lines
-- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120702/46a7d4fd/attachment.html>

Reply by email

Hans-Peter Diettrich
to Mattias Gaertner: On Mon, 2 Jul 2012 22:00:05 +0300 Why not simply drop a ApplicationProperties onto the…
Show quoted text 13 lines
On Mon, 2 Jul 2012 22:00:05 +0300 ik wrote: > I'm trying to capture the windows message WM_QUERYENDSESSION (that exists > on JwaWinUser). > > I did something like this: > > TForm1 = class(TForm) > ... > private > procedure WMQueryEndSession(var Msg : TLMessage); message > WM_QUERYENDSESSION

This message most probably is sent to the application, not to all of its forms. That's why:

Why not simply drop a ApplicationProperties onto the form and set the OnQueryEndSession event?

Or you add an handler manually to your Application object.

DoDi

Reply by email

ik
to Ludo Brands
Ludo Brands wrote 9 lines
> It looks like the message never fires. Only few windows messages can be intercepted with the message directive. Inserting your own WndProc in the message chain is a solution: http://wiki.freepascal.org/Win32/64_Interface/ja#Processing_non-user_message s_in_your_window

There are few problems there that I found after a lot of testing. For example WndProc that does not execute, also my own TApplication that inherited from forms.TApplication did not got the message fires.

So, I'm going to use the Application.OnQuery... Instead and get over with it

Show quoted text 10 lines
Ludo -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20120704/a7353be3/attachment.html>

Reply by email