3
votes

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.

1
You'll probably get better answers if you ask these questions separately. - Wouter van Nifterick
You might want to handle WM_GETMINMAXINFO. take a look here. HTH - kobik
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
No, just the SHIFT key must be held :) - maxfax

1 Answers

2
votes

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.