0

我正在尝试调整非无边界表单(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;
4

1 回答 1

2

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将再次被调用。当然,您将失去 VCL 样式处理程序WM_NCHITTEST提供的任何功能,但我怀疑这正是您想要的。

于 2017-06-29T08:13:23.860 回答