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

1

7

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?

Nieves answered 24/12, 2013 at 16:40 Comment(0)
R
9

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;
Rockribbed answered 24/12, 2013 at 16:46 Comment(1)
Note: In newer Delphi versions, if Application.MainFormOnTaskbar is True, the main form's window state will be wsMinimized.Erythroblast

© 2022 - 2024 — McMap. All rights reserved.