Skullcode 0 Posted September 21, 2020 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
Lars Fosdal 1792 Posted September 21, 2020 if WinApi.Windows.IsIconic(Application.MainForm.Handle) then begin // Log something end; https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-isiconic?redirectedfrom=MSDN 1 Share this post Link to post
FPiette 382 Posted September 21, 2020 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; 1 Share this post Link to post
Der schöne Günther 316 Posted September 21, 2020 The global application object has an OnMinimize event. 1 Share this post Link to post
Remy Lebeau 1393 Posted September 21, 2020 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. 5 Share this post Link to post
#ifdef 12 Posted February 23 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 😞 Share this post Link to post
Der schöne Günther 316 Posted February 23 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. 1 Share this post Link to post
#ifdef 12 Posted February 23 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