How to Hide my Forms when they are minimized?
Asked Answered
D

1

5

Other than my main form, I need my forms to notify my main form and hide when I minimize them (instead of beeing minimized to the desktop window).

How can this be done?

My forms are created like this: How to make my Forms always to be on top my main form?

Disaccharide answered 13/12, 2013 at 19:18 Comment(0)
W
7

Handle the WM_SYSCOMMAND message to detect the minimize:

type
  TMyForm = class(TForm)
  ....
  protected 
    procedure WMSysCommand(var Message: TWMSysCommand); message WM_SYSCOMMAND;
  ....
  end;
....
procedure TMyForm.WMSysCommand(var Message: TWMSysCommand);
begin
  if Message.CmdType and $FFF0 = SC_MINIMIZE then
    Hide
  else
    inherited;
end;

You can also notify the main form at this point by whatever mechanism you choose.

Wiesbaden answered 13/12, 2013 at 20:11 Comment(2)
Why not call inherited in any case (like you did in your initial answer)?Disaccharide
Because that will minimise the form window before hiding it. May as well just hide it.Wiesbaden

© 2022 - 2024 — McMap. All rights reserved.