Author: Jonas Bilinkevicius
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.
1 { ... }2 private3 FOldSize, FNewSize: TRect;
4 5 procedure WMEnterSizeMove(var msg: TMessage); message WM_ENTERSIZEMOVE;
6 procedure WMExitSizeMove(var msg: TMessage); message WM_EXITSIZEMOVE;
7 { ... }8 9 procedure TProdBuilderMainForm.WMEnterSizeMove(var msg: TMessage);
10 begin11 FOldSize := BoundsRect;
12 end;
13 14 procedure TProdBuilderMainForm.WMExitSizeMove(var msg: TMessage);
15 begin16 FNewSize := BoundsRect;
17 { ... do something with the sizes}18 end;