Search code examples
delphiwindowmdichildwindowmaximize

Delphi: Maximize a Child Window in MDI Project


There is the good component to maximize a child window in a client area (the SHIFT key must be held) - NLDExtraMDIProps.

Or this code can be used:

procedure WMSIZE(var Msg: TMessage); message WM_SIZE;

procedure TForm2.WMSIZE(var Msg: TMessage);
begin
  inherited;
  if Msg.WParam = SIZE_MAXIMIZED then
  begin
    ShowWindow(Handle, SW_RESTORE);
    Left := 0;
    Top := 0;
    Width := Form1.ClientWidth - 4; // The BORDER
    Height := Form1.ClientHeight - 4;
  end;
end;

But maximizing isn't real maximizing. The child window is only aligned to the client area. It must automatically resize and fit the client area when the parent window is resized, the maximize/restore system button must change etc.

I try to accomplish effects that are described below.

As you see on the pictures the child windows are maximized, and

  1. they don't take the entire parent window (only the client area).

  2. It's impossible to move them over the caption/title bar because they are maximized.

  3. They have the restore button, not the maximize button any more.

  4. They are aligned to the client area (resizing of the parent window causes resizing of the child one withing the client area).

The code in my question and the component don't do like the child windows on the pictures.

Can we make a window really maximized (not just aligned)?

Not maximized (not good; the component and the code from my question maximize like on these pictures):

enter image description here enter image description here

Maximized (what I need):

enter image description here enter image description here


Solution

  • I do not understand your problem. Maximizing an MDI child window is done:

    • programmatically: by using ShowWindow(ActiveMDIChild.Handle, SW_MAXIMIZE),
    • manually: by clicking the Maximize border icon, or by double clicking on the form caption.

    Both these actions result in:

    • the disappearance of the child window border (collapses into the MDI form border),
    • the addition of small border icons (for the child window) to the main menu bar,
    • a resize effect similar to that of Align=alClient.

    To restrict the available space for the child windows within the main form, make sure to align windowed controls to edges of the form.

    Setting the Align or Anchors properties for MDI child windows has no effect: they are not part of the default VCL aligning implementation anymore; Windows has taken over that job.

    If you want to intervene on the resizing of an MDI child, then handling WM_SIZE is the wrong approach, because that message is send áfter the resize. Instead, handle WM_SYSCOMMAND as I explained here.

    As for my component that you refer to:

    • Manually maximizing by clicking the Maximize border icon does exactly thát: a default maximize operation as outlined above,
    • Manually maximizing by clicking the Maximize border icon - while holding the Shift key - does resize the child window to the largest spare space within the MDI form. In this case, resizing the MDI main form does nót resize the MDI child forms.