Re:Newbie Q: Max Form Size
Quote
David Carvalho wrote in message
<7056l6$rj...@holly.prod.itd.earthlink.net>...
Quote
>Just a quick newbie question. How do I set the maximum dimensions for my
>form? I've come up with a simple solution but it isn't as pretty as I'd
>like:
> If Height > 610 then
> Height := 610;
> If Width > 800 then
> Width := 800;
>Using this makes the form have a '{*word*221} band' type effect when the user
>tries to stretch it farther than its maximum dimensions (it snaps back).
>What I'd like is for the form to just stop at its max limit. How would I
do
>this? Thanks for any help. :)
The answer lies in delving into the Windows API for the
WM_GETMINMAXINFO message. Windows sends this
message to a window that is being resized to request
maximum or minimum sizes.
1. Add the following procedure declaration to the private
section of your form declaration:
private
:
procedure WmGetMinMaxInfo(var Msg : TMessage); message WM_GETMINMAXINFO;
:
2. In the implementation section of the unit, write the body
of the procedure (replace "TForm1" with whatever your form
is called):
procedure TForm1.WmGetMinMaxInfo(var Msg : TMessage);
begin
inherited;
PMinMaxInfo(Msg.LParam)^.ptMaxTrackSize.X := 800; //max width
PMinMaxInfo(Msg.LParam)^.ptMaxTrackSize.Y := 610; //max height
end;
That's it! The details are a little messy - basically the LParam of
the message is a pointer to a MINMAXINFO structure that Windows
has created. We've typecasted the LParam to a pointer to this
structure, and then dereferenced the pointer with "^".
Because Msg is a "var" parameter, we can modify the contents,
and Windows will know our desired dimensions when the message
handler returns.
If you want minimum sizes, use "ptMinTrackSize".
HTH
-
Jeremy Collins
Kansai Business Systems