Mirror

How to get the width and height of a MDI child form while dragging (Views: 101)


Problem/Question/Abstract:

I need to know how to get the width and height of a MDI child window (or of an aligned component) before (!) and after scaling it with mouse dragging (e.g. dragging on the right bottom corner of the window). Which event provides these values at which time?

Answer:

There is no event directly usable for this but it can be done with a bit of API mixed in. When the user starts to drag on the border the window gets a WM_ENTERSIZEMOVE message, when the mouse goes up again it gets a WM_EXITSIZEMOVE message. So these are ideally suited to record old and new size. Note that the messages (as their name implies) are also send when the user moves the window by dragging on the caption. In that case the two sizes will simply be equal, so that is easy to test.

{ ... }
private
FOldSize, FNewSize: TRect;

procedure WMEnterSizeMove(var msg: TMessage); message WM_ENTERSIZEMOVE;
procedure WMExitSizeMove(var msg: TMessage); message WM_EXITSIZEMOVE;
{ ... }

procedure TProdBuilderMainForm.WMEnterSizeMove(var msg: TMessage);
begin
  FOldSize := BoundsRect;
end;

procedure TProdBuilderMainForm.WMExitSizeMove(var msg: TMessage);
begin
  FNewSize := BoundsRect;
  { ... do something with the sizes}
end;

<< Back to main page