-2

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

NGLN
  • 43,011
  • 8
  • 105
  • 200
maxfax
  • 4,281
  • 12
  • 74
  • 120

2 Answers2

6

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.
Community
  • 1
  • 1
NGLN
  • 43,011
  • 8
  • 105
  • 200
  • Hi NGLN! Please see the difference on the pictures in my question. The child windows are maximized, and they don't take the entire main window (only the client area). It's impossible to move them because they are maximized. They have the restore button, not the maximize button any more. 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 your component don't copy behavior of the child windows on the pictures. – maxfax Feb 27 '12 at 04:25
  • the first pictures are your component and the code in my question (the same effect). The last 2 - how must be. – maxfax Feb 27 '12 at 04:35
  • I still do not understand your problem. If you are doing all well (setting `FormStyle=fsMDIForm` for the main form and `FormStyle=fsMDIChild` for the child forms), then there is something else wrong. – NGLN Feb 27 '12 at 04:42
  • Do you want to say that your component do all these: 1) the child window doesn't take the entire parent window (only the client area). 2) It's impossible to move the child window over the caption/title bar because it's maximized. 3) The child window has the restore button, not the maximize button any more. 4) The child window is aligned to the client area (resizing of the parent window causes resizing of the child one withing the client area)??? – maxfax Feb 27 '12 at 04:48
  • Your component does only the first paragraph for me :( I need to do the other 3 paragraphs. – maxfax Feb 27 '12 at 04:51
  • My component doesn't do all of that: Windows should! You are making a mistake: maximizing an MDI child SHOULD do what you are asking, without any code or component! My component is only for convenience in case you dón't want default maximization. – NGLN Feb 27 '12 at 04:58
  • Ok, I understand what your component does (and what it doesn't). It's good for another issue. Can you help me with my issue? You know what I need. That is why I asked this question. – maxfax Feb 27 '12 at 05:09
  • What do you want us more to answer then just to maximize the MDI child form? If that doesn't work, then hell I don't know anymore. Did you try an empty test project? – NGLN Feb 27 '12 at 05:30
  • I even tried your project from http://www.nldelphi.com/forum/showthread.php?t=20728 . It works! I don't say that something doesn't work - your component works! BUT I need to do 4 paragraphs in my question. Your component does only the first paragraph. I know that your components doesn't do the other 3 paragraphs, I do! And I don't say that it's buggy , it works properly. Could you help to do the other 3 paragraphs? Your component and the code were mentioned as an example only. – maxfax Feb 27 '12 at 05:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/8247/discussion-between-ngln-and-maxfax) – NGLN Feb 27 '12 at 06:21
-1
if (Msg.WParam = SIZE_MAXIMIZED) then
  begin
    Left := 0;
    Top := 0;
    Width := frmMain.ClientWidth - 4;
    Height := frmMain.ClientHeight - 4;
    SendMessage(Handle, WM_SIZE, SIZE_RESTORED, 0);
  end;
fedorqui
  • 275,237
  • 103
  • 548
  • 598
Mihai
  • 1