Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch onMinimize Event For a Form (Delphi)

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

like image 644
Jessica Avatar asked Feb 18 '14 17:02

Jessica


2 Answers

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).

like image 157
Sertac Akyuz Avatar answered Oct 18 '22 18:10

Sertac Akyuz


second is better. as WindowState is not necessarily wsMinimized.

like image 43
Anonimous Avatar answered Oct 18 '22 17:10

Anonimous