Minimize Delphi application

Posted by newComer on June 11, 2001

could somebody tell me how to make an 'if else' comparison for minimize window?

i should be like this:

if application minimize then
....
else
...

what is the proper syntax to do this?

Re: webmaster Guido on June 16, 2001

Application.Active is FALSE when the application is minimized. The code is:

if not Application.Active then
...
else 
...

Let's look at an example: using a timer, you want to check every minute if your application's main form is visible to the user, and if not, "bring it back" again.

How could the main form have been ordered to "disappear"?

1. Under program control, with "Application.Minimize", which will hide all the forms of the application.
2. By the user, who clicked on the Minimize button in the title bar of the main form. This will automatically generate an "Application.Minimize".
3. Under program control, with "MainForm.WindowState := wsMinimized".
Important note: this does NOT automatically generate an "Application.Minimize"!
4. Under program control, with "MainForm.Visible := False" -- this is the same as "MainForm.Hide".

When the user clicks the main form's minimize button, the Delphi application is minimized. But contrary to other Windows applications, in a Delphi program that main form is NOT the application's "main window". In fact, every Delphi application has an extra invisible (zero sized) window, which acts as the main window. This hidden main window receives messages from Windows and it communicates with the application's main form. When a click on the main form's minimize button is received, this is internally translated to an Application.Minimize command. In other words: minimizing the main form with "WindowState := wsMinimized" is not the same as "Application.Minimize"!

The code below will "bring back" the main form, no matter what the reason was why it has disappeared:

procedure TForm1.Timer1Timer;
begin
  if not Application.Active then 
    Application.Restore;
  if WindowState = wsMinimized then 
    WindowState = wsNormal;
  if not Visible then 
    Visible := True;
end;