4
votes

in delphi mdi application there is need to show a child window with its caption in Mainform client area when maximize button is pressed using

Win32Check(Windows.GetClientRect(ClientHandle, aTRect));

MDIChild1.BoundsRect := aTRect;

functions.

So, how we can prevent a MDI child from being maximized when maximize button is pressed?

I've tried to do it using

procedure TChildText.WMSYSCOMMAND(var Message: TWMSYSCOMMAND);
var
  aTRect:TRect;
begin
  inherited;
  case message.CmdType of
    SC_MAXIMIZE: 
      begin
        Win32Check(Windows.GetClientRect(MainForm.ClientHandle, aTRect));
        BoundsRect := aTRect;
      end;
  end;
end;

with no result.

1
Please show the complete message handlerDavid Heffernan
It's unreadable there. Please delete the comment and edit that code into the question. Please take care over the formatting so that the code is as readable as possible. The code in the question at the moment is scrappy. Such details are very important.David Heffernan
I've removed Inherited; Line and it works. Thanks.Avrob
Thank you for the edits. Whether or not there was a call to the inherited handler was what I was trying to find out.David Heffernan
Because then the user would need to manually size the window to the client area, @Honza. This way, using the maximize button "almost" maximizes the window automatically. The goal here is to slightly redefine what maximization means, not to disable it entirely.Rob Kennedy

1 Answers

1
votes
procedure TChildText.WMSYSCOMMAND(var Message: TWMSYSCOMMAND);
var
  aTRect:TRect;
begin
  if message.CmdType = SC_MAXIMIZE then
  begin
    Win32Check(Windows.GetClientRect(MainForm.ClientHandle, aTRect));
    BoundsRect := aTRect;
    message.CmdType := SC_RESTORE;
  end;
  inherited;
end;