2
votes

In a Delphi 10.4 VCL Application, I need to detect when the FORM RESIZING ENDS. (E.g. after the user resized the Form by dragging its size-grip).

So I have placed a TApplicationEvents component on the form and created its OnMessage event-handler, trying to catch the WM_EXITSIZEMOVE message:

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;

But the event-handler with WM_EXITSIZEMOVE is not executed after resizing the Form.

So how can I detect the Form Resize END, maybe by using the TApplicationEvents component?

1

1 Answers

4
votes

The WM_EXITSIZEMOVE message is sent directly to the window. Thus, it is not detected by the TApplicationEvents's OnMessage handler, because that only detects messages that are posted to the main message queue.

So, you need to override the form's WndProc() instead:

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;

Or, you can use a message procedure instead:

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;

However, beware that this message, as its name implies, is not only sent when the window has been resized, but it is also sent after the window has been moved. And in both cases, only when the operation involved a modal loop.

For instance, if you maximize the window by double-clicking its title bar, or if you move it to a different screen by pressing Shift+Win+Right, this message isn't sent at all.