【问题标题】:Hide scroll bars in MDI Form using VCL Styles使用 VCL 样式隐藏 MDI 表单中的滚动条
【发布时间】:2020-07-29 13:29:36
【问题描述】:

在主要包含MDI parent form 的桌面应用程序上工作,其中模块显示为MDI Child form。 在将子窗体移动到客户端限制之外时,我想摆脱滚动条。我已经将AutoScroll 属性设置为False 并尝试了以下解决方案:

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;

如果没有启用 VCL 样式,它就像一个魅力。否则,我无法捕捉到WM_NCCALCSIZE 消息。

我正在使用 Delphi Rio 10.3.3VCL Styles

【问题讨论】:

  • 你为什么要这样钩住客户端 WndProc?在主窗体中覆盖ClientWndProc 不是更容易吗?

标签: delphi scrollbar vcl delphi-10.3-rio vcl-styles


【解决方案1】:

找到了注册StyleHook的解决方法:

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

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

开始执行时:

  TCustomStyleEngine.RegisterStyleHook(TForm,TFixedFormStyleHook);

【讨论】:

  • 不过,此解决方案并非万无一失。当您在父级中移动 MDI 子级时,它将起作用。但是,当您以需要滚动条的方式调整父级的大小时,滚动条会出现。
猜你喜欢
  • 2015-11-05
  • 2013-10-26
  • 1970-01-01
  • 1970-01-01
  • 2015-12-05
  • 2013-12-17
  • 2014-04-07
  • 1970-01-01
  • 2015-10-29
相关资源
最近更新 更多