00 Votes

Lazarus: React to minimization of the application window

Question by Guest | 2015-03-22 at 17:55

I would like to execute some code whenever the user of my application is minimizing the program window. Unfortunately, I cannot find an appropriate event in the window properties (that is TForm). I have searched for something like OnMinimize or alike.

I have found a code for Delphi, but this code is working with Windows messages and I would like to live without them in my application.

Isn't there any simple way in Lazarus? Or do I have to deal with the messages provided by Windows?

ReplyPositiveNegative
Avatar
0Best Answer0 Votes

Your Form should provide the event OnFormWindowStateChange that is executed whenever something changes at the window (minimizing, maximizing, go back to the normal size).

In this procedure, you can just ask for the current state and execute your desired code:

procedure TForm1.FormWindowStateChange(Sender: TObject);
begin
  if Form1.WindowState = wsMinimized then ...
  if Form1.WindowState = wsMaximized then ...
  if Form1.WindowState = wsNormal then ...
end;   

If the property WindowState of your form has the value wsMinimized, the window has just been minimized, if the property is wsMaximized, the window has just been maximized.
2015-03-23 at 15:29

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.