Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Delphi main form WindowState returned as "wsNormal" when the window is minimized?

I have a monitoring application written in Delphi 7 that runs on part of a secondary monitor. I'd like to have it restore itself to normal visibility if the window gets minimized (for example if I use the the "Windows-D" (view desktop) command on the main monitor)

I tried this code activated by a timer every few seconds:

    if (Mainform.WindowState <> wsNormal ) then
        Mainform.WindowState := wsNormal;      {restore main window if minimized}

It doesn't work. To debug it, I changed the code to log the value of Mainform.WindowState to a file as the program is running. The value remains wsNormal even when the main form's window is minimized. Why?

like image 382
tim11g Avatar asked Dec 24 '13 16:12

tim11g


1 Answers

Because the main form is not minimized. When the application is minimized, VCL just hides the main form. You can test if the application is minimized and restore if so:

if IsIconic(Application.Handle) then
  Application.Restore;
like image 107
Sertac Akyuz Avatar answered Oct 03 '22 19:10

Sertac Akyuz