1

Working on a desktop application that consists mainly in a MDI parent form, where modules are shown as MDI Child form. I want to get rid of the scroll bars when moving a child form outside the client limits. I've already set the AutoScroll property to False and tried the following solution:

procedure TForm1.FormCreate(Sender: TObject);
begin
  if ClientHandle <> 0 then
  begin
    if (not (GetWindowLong(ClientHandle, GWL_USERDATA) <> 0)) then
    begin
      SetWindowLong(ClientHandle, GWL_USERDATA,
      SetWindowLong(ClientHandle, GWL_WNDPROC,
      Integer(@ClientWindowProc)));
    end;
  end;        
end;

function ClientWindowProc(wnd: HWND; Msg: Cardinal;  wParam, lParam: Integer): Integer; stdcall;
var
  f: Pointer;
begin
  f := Pointer(GetWindowLong(wnd, GWL_USERDATA));

  case Msg of
    WM_NCCALCSIZE: begin
                     if (GetWindowLong(wnd, GWL_STYLE) and (WS_HSCROLL or WS_VSCROLL)) <> 0 then
                       SetWindowLong(wnd, GWL_STYLE, GetWindowLong(wnd, GWL_STYLE) and not (WS_HSCROLL or WS_VSCROLL));
                   end;
  end;

  Result := CallWindowProc(f, wnd, Msg, wparam, lparam);
end;

It works like a charm if VCL Styles are not enabled. Otherwise, I cannot catch the WM_NCCALCSIZE message.

I'm using Delphi Rio 10.3.3 with VCL Styles on.

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
Carlos M
  • 43
  • 7
  • Why do you hook client WndProc that way? Isn't it easier to override [`ClientWndProc`](http://docwiki.embarcadero.com/CodeExamples/Sydney/en/ClientWndProc_(Delphi)) in your main form? – Peter Wolf Jul 30 '20 at 14:47

1 Answers1

1

Found a workaround registering a StyleHook:

TFixedFormStyleHook = class(TFormStyleHook)
  public
    procedure WMMDIChildMove(var Message: TMessage); message WM_MDICHILDMOVE;
  end;

 procedure TFixedFormStyleHook.WMMDIChildMove(var Message: TMessage);
  begin
    handled := true;
  end;

On begin execution:

  TCustomStyleEngine.RegisterStyleHook(TForm,TFixedFormStyleHook);
Carlos M
  • 43
  • 7
  • This solution isn't bulletproof, though. It will work when you move MDI child inside the parent. But the scrollbar will appear when you resize the parent in such way that scrollbars are needed. – Peter Wolf Jul 30 '20 at 14:55