问题描述
在Delphi 10.4 VCL应用程序中,我需要检测FORM RESIZING ENDS 的时间。 (例如,在用户通过拖动表格的大小尺寸来调整其大小之后)。
因此,我在表单上放置了一个TApplicationEvents
组件,并创建了它的OnMessage
事件处理程序,试图捕获WM_EXITSIZEMOVE
消息:
procedure TformMain.ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);
begin
if (Msg.Message = WM_EXITSIZEMOVE) then
begin
CodeSite.Send('TformMain.ApplicationEvents1Message: WM_EXITSIZEMOVE');
end;
end;
但是在调整表单大小后,不会执行带有WM_EXITSIZEMOVE
的事件处理程序。
那么,如何通过使用TApplicationEvents组件来检测“表单调整大小” END?
解决方法
WM_EXITSIZEMOVE
消息直接发送到窗口。因此,TApplicationEvents
的{{3}}处理程序不会检测到该消息,因为它仅检测到已发布到主消息队列的消息。
因此,您需要改写表单的WndProc()
:
type
TForm1 = class(TForm)
private
protected
procedure WndProc(var Message: TMessage); override;
public
end;
implementation
procedure TForm1.WndProc(var Message: TMessage);
begin
inherited;
case Message.Msg of
WM_EXITSIZEMOVE:
ShowMessage('Yes!');
end;
end;
或者,您可以改用OnMessage
:
type
TForm1 = class(TForm)
private
protected
procedure WMExitSizeMove(var Message: TMessage); message WM_EXITSIZEMOVE;
public
end;
implementation
procedure TForm1.WMExitSizeMove(var Message: TMessage);
begin
inherited;
ShowMessage('Yes!');
end;
但是,请注意,此消息,顾名思义,不仅在调整窗口大小时发送,而且在移动窗口后发送。而且在这两种情况下,仅当操作涉及模式循环时。
例如,如果通过双击窗口的标题栏来最大化窗口,或者通过按 Shift + Win + 对,此消息根本不会发送。