4

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.

Avrob
  • 533
  • 2
  • 10
  • 20
  • Please show the complete message handler – David Heffernan Dec 14 '14 at 22:42
  • 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 Dec 15 '14 at 08:23
  • I've removed Inherited; Line and it works. Thanks. – Avrob Dec 15 '14 at 08:33
  • 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 Dec 15 '14 at 08:54
  • Why don't you just remove `biMaximize` from `BorderIcons` to prevent maximization in the first place. – Honza R Dec 15 '14 at 09:20
  • 2
    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 Dec 15 '14 at 13:55
  • What about having the MDI child handle the [`WM_GETMINMAXINFO`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms632626.aspx) message instead? It could then adjust the fields of the [`MINMAXINFO`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms632605.aspx) struct as needed, and thus not have to handle `WM_SYSCOMMAND` and risk breaking it. – Remy Lebeau Dec 15 '14 at 20:09

1 Answers1

1
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;
Avrob
  • 533
  • 2
  • 10
  • 20
  • 3
    If this resolves your problem, then instead of `Exit` you can use `else inherited;`. In any case return 0 to the `Message.Result`. – TLama Dec 15 '14 at 08:57
  • 2
    You are right. But today I noticed, that maximize button does not respons when MDIchild window is minimized. So, instead the Exit command I set the message.CmdType:= SC_RESTORE. – Avrob Dec 15 '14 at 14:26