Catch onMinimize Event For a Form (Delphi)
Asked Answered
T

2

7

I found 2 ways for catching onMinimize event.

First: On FormResize event:

if MyForm.WindowState = wsMinimized then ......

Second: Declaring the message handler like this:

procedure WMSize(var Msg: TMessage); message WM_SIZE;

And then:

procedure TForm57.WMSize(var Msg: TMessage);
begin
  if Msg.WParam  = SIZE_MINIMIZED then ....
end;

Which way is better?!

Trahan answered 18/2, 2014 at 17:52 Comment(3)
The one which is better readable for you.Delphine
Which one is most optimized?Trahan
Don't worry about optimizing until you've identified a reason to do so (by profiling to track down an actual performance problem). Until then, do whichever is more readable and easiest to maintain.Galvin
T
7

OnResize is fired in response to the same message (WM_SIZE). Unless you need to react before the VCL handles the message (update scrollbars, align controls etc.), you don't need to attach a message handler. Otherwise, be sure to handle it before the inherited call (which is missing in your sample).

Tenorio answered 18/2, 2014 at 18:10 Comment(0)
A
1

second is better. as WindowState is not necessarily wsMinimized.

Acrophobia answered 30/5, 2014 at 22:19 Comment(1)
Every WM_SIZE message will cause an OnResize event fired, whatever your window state is.Tenorio

© 2022 - 2024 — McMap. All rights reserved.