启用Vcl样式时调整bsNone表单的大小

时间:2017-06-29 05:19:27

标签: delphi resize vcl-styles borderless

我正在尝试调整非无边框形式(bsNone边框样式)。可以使用以下代码完成此操作,但仅当应用程序未启用VCL样式时才能使用。

protected
   procedure WMNCHitTest(var message: TWMNCHitTest); message WM_NCHITTEST;
....

procedure TForm1.WMNCHitTest(var message: TWMNCHitTest);
const
  EDGEDETECT = 7;
var
  deltaRect: TRect;
begin
  inherited;
  if BorderStyle = bsNone then
    with Message, deltaRect do
    begin
      Left   := XPos - BoundsRect.Left;
      Right  := BoundsRect.Right - XPos;
      Top    := YPos - BoundsRect.Top;
      Bottom := BoundsRect.Bottom - YPos;
      if (Top < EDGEDETECT) and (Left < EDGEDETECT) then
        Result := HTTOPLEFT
      else if (Top < EDGEDETECT) and (Right < EDGEDETECT) then
        Result := HTTOPRIGHT
      else if (Bottom < EDGEDETECT) and (Left < EDGEDETECT) then
        Result := HTBOTTOMLEFT
      else if (Bottom < EDGEDETECT) and (Right < EDGEDETECT) then
        Result := HTBOTTOMRIGHT
      else if (Top < EDGEDETECT) then
        Result := HTTOP
      else if (Left < EDGEDETECT) then
        Result := HTLEFT
      else if (Bottom < EDGEDETECT) then
        Result := HTBOTTOM
      else if (Right < EDGEDETECT) then
        Result := HTRIGHT
    end;

我也尝试过这样的事情并且它有相同的结果。然后,当启用VCL样式时,如何使其可调整大小?

非常感谢你。

procedure CreateParams(var params: TCreateParams); override;
    ...
    procedure TForm1.CreateParams(var params: TCreateParams);
          begin
            BorderStyle := bsNone;
            inherited;
            params.ExStyle := params.ExStyle or WS_EX_STATICEDGE;
            params.Style   := params.Style or WS_SIZEBOX;
          end;

1 个答案:

答案 0 :(得分:1)

VCL样式破坏WM_NCHITTEST消息处理程序的原因是表单的样式挂钩直接处理WM_NCHITTEST。您可以覆盖它并重新获得如下控制:

protected
  function DoHandleStyleMessage(var Message: TMessage): Boolean; override;

....

function TForm1.DoHandleStyleMessage(var Message: TMessage): Boolean;
begin
  if Message.Msg=WM_NCHITTEST then begin
    Result := False;
  end else begin
    Result := inherited;
  end;
end;

现在将再次调用WM_NCHITTEST的事件处理程序。当然,您将失去WM_NCHITTEST的VCL样式处理程序提供的任何功能,但我怀疑这正是您想要的。