3

How can I maximize a child window that fits only the client area but not an entire parent window? I don't want that the child window disappears under a main menu or other controls of the parent window.

I have this code

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 it's not good enough. The window is actually not maximized. If to change SW_RESTORE to SW_MAXIMIZE then the child window looks buggy.

maxfax
  • 4,281
  • 12
  • 74
  • 120
  • 3
    You'll probably get better answers if you ask these questions separately. – Wouter van Nifterick Feb 24 '12 at 10:12
  • You might want to handle `WM_GETMINMAXINFO`. take a look [here](http://social.msdn.microsoft.com/forums/en-US/windowsuidevelopment/thread/d6cb9184-826e-466d-9f48-7ee4e316ac58/). HTH – kobik Feb 24 '12 at 19:04
  • 1
    Sounds to me like when you maximize the child window it maximizes to the screen not the mdi parent.If this is true, then it sounds like you simply do not have the FormStyle property set correctly for both child and parent windows – GDF Feb 24 '12 at 20:39
  • No, just the SHIFT key must be held :) – maxfax Feb 26 '12 at 04:15

1 Answers1

2

Normally, the MDI main form's client space should be calculated automatically to the space without menu or bars, provided that those bars are aligned to an edge of the form.

When a bar or other controls are not aligned, then you indeed have to adjust yourself. Handle WM_NCCALCSIZE to tell windows your form has deviating client rect dimensions.

Or take a look at NLDExtraMDIProps in which I catch WM_SYSCOMMAND when WParam and $FFF0 = SC_MAXIMIZE to adjust the size of a MDI child window. The component provides in a few extra properties like: BackgroundPicture, CleverMaximizing, ShowClientEdge and ShowScrollBars.

NGLN
  • 43,011
  • 8
  • 105
  • 200
  • NGLN, thanks a lot for the answer! I tried your component, it's really helpful! Scroll bars and a border are hidden. But CleverMaximizing doesn't work for me, a child window still takes a whole window, not a client area. I have two left & top aligned bars. Delphi XE2. Could you help me with maximizing? Please see my edited question. – maxfax Feb 24 '12 at 16:13
  • I suspect you are drawing a wrong conclusion. Retry your test with a control in the top left corner of the MDI child and it will appear next to the panel and below the menu bar. The size of the client window is controlled by `TCustomForm.AlignControls`; I don't see why that should vary or change in XE2. – NGLN Feb 24 '12 at 19:56
  • Thanks NGLN!!! Your answer is really valuable. And I'm sorry, I didn't know about the SHIFT key. Another question appeared, I'll ask it separately. – maxfax Feb 27 '12 at 03:18