Delphi: Maximized Child Form in MDI Application

泪湿孤枕 提交于 2020-01-04 05:20:13

问题


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:


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.



来源:https://stackoverflow.com/questions/9428145/delphi-maximized-child-form-in-mdi-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!