启用 Vcl 样式时调整 bsNone 窗体的大小
Resizing bsNone Form when Vcl Styles Enabled
我正在尝试调整非无边框表单(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;
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 样式处理程序提供的任何功能,但我怀疑这正是您想要的。
我正在尝试调整非无边框表单(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;
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 样式处理程序提供的任何功能,但我怀疑这正是您想要的。