Jump to content
Skullcode

check if App Minimized

Recommended Posts

when i minimize My Vcl Application i do the following check in a Timer

 

 

if WindowState = wsMinimized  then
begin

//do some logging

end;

but this if condition doesn't detect whether the app is Minimized or not 

 

any idea how to detect if the app Minimized ?

Share this post


Link to post

The answer given by @Lars Fosdalis correct, but there is an alternative method: instead of querying the status with a timer, you can simply install a handler for WM_SIZE message and inspect the SizeType argument. When the windows is minimized (become iconic), SizeType value is SIZEICONIC (1). See Microsoft documentation for WM_SIZE


 

  TForm1 = class(TForm)
  private
    procedure WMSize(var Msg: TWMSize); message WM_SIZE;
  end;


procedure TForm1.WMSize(var Msg: TWMSize);
begin
   if Msg.SizeType = SIZEICONIC then begin
       // Do something
   end;
end;

 

  • Like 1

Share this post


Link to post

What is the TApplication.MainFormOnTaskbar property set to?

 

If MainFormOnTaskbar is True, then minimizing the MainForm will minimize the MainForm window to the Taskbar.  In which case, checking TForm.WindowState or IsIconic(MainForm.Handle) should work.

 

But if MainFormOnTaskbar is False, then minimizing the MainForm will hide the MainForm window and minimize the TApplication window to the Taskbar.  In which case, checking IsIconic(Application.Handle) should work.

  • Like 5

Share this post


Link to post
On 9/21/2020 at 9:52 PM, Der schöne Günther said:

The global application object has an OnMinimize event.

It doesn't work with Win+D 😞

 

image.thumb.png.ce84c356e4483732b1ae5d979a90e207.png

Share this post


Link to post

That is because Win+D does not minimise windows. It brings the desktop window to the foreground.

You can validate this by pressing Win+D again which will send the desktop to the back again, and all windows are just like before.

 

What for Win+M? This will actively minimise the windows, and this should get handled by the OnMinimize event.

  • Like 1

Share this post


Link to post
2 hours ago, Der schöne Günther said:

That is because Win+D does not minimise windows.

Em.... but the size of the Form1 changes (this can be seen on OnResize).

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×