Catch the Minimize event for a form (Delphi)

I found 2 ways to catch onMinimize event.

First: in the FormResize event:

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

Second: Declaring a message handler as follows:

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 ?!

+3
source share
2 answers

OnResizeruns in response to the same message ( WM_SIZE). If you do not need to respond before the VCL processes the message (update scrollbars, align controls, etc.), you do not need to attach a message handler. Otherwise, remember to process it before the call inherited(which is not in your example).

+3
source

seconds are better. since WindowState is not necessarily wsMinimized.

+1
source

All Articles