Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

keeping MDI Child forms within Main form

40 views
Skip to first unread message

Dirk Naudts

unread,
Oct 21, 2001, 7:35:50 AM10/21/01
to
Hi,

I'm looking for a way to "block" MDI-Children to move beyond the main-forms'
borders.
The main form is shown full screen, and shouldn't show scrollbars.
Childforms can be moved by the user, but not leave the screen borders.

How can I accomplish this ?

Thanks,

Dirk Naudts.

Johnnie

unread,
Oct 21, 2001, 10:58:43 AM10/21/01
to
>Hi,
>
>I'm looking for a way to "block" MDI-Children to move beyond the
>main-forms' borders.

You can catch the WM_Move message and do what ever you want with it

here is a small sample that will try to prevent a form from moving outisde
the screen it is not working correctly as you will see but I have
no time to make it work correctly right now. It will start you of though.

Regards
Johnnie.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
TForm1 = class(TForm)
private
{ Private declarations }
procedure WMMove(var Message: TWMMove); message WM_MOVE;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

Procedure Tform1.WMMove(Var MEssage:TWMMove);
Var
Exc: Boolean;
begin
If (message.XPos + Width) > Screen.Width then begin
left := screen.Width - width;
exc := true
end;
if (Message.YPos + height) > Screen.Height then
begin
top :=screen.Height - Height;
exc:=true;
end;
if exc then Message.Result:=0;
end;

end.

Peter Below (TeamB)

unread,
Oct 21, 2001, 1:12:08 PM10/21/01
to
In article <3bd2b3cf_1@dnews>, Dirk Naudts wrote:
> I'm looking for a way to "block" MDI-Children to move beyond the main-forms'
> borders.
> The main form is shown full screen, and shouldn't show scrollbars.
> Childforms can be moved by the user, but not leave the screen borders.
>
Limit a child form to the parents clientwindow

> Is it possible to limit the MDI client form movement, so that the form
> cannot be moved outside the client area of the MDI form?

Yes, you can handle the WM_WINDOWPOSCHANGING message in the child forms and
modify the message parameters if needs be to keep the child fully visible.
Of course this is a breach of the standard Windows behaviour.

private // in form declaration
Procedure WMWINDOWPOSCHANGING(Var msg: TWMWINDOWPOSCHANGING);
message WM_WINDOWPOSCHANGING;


Procedure TForm1.WMWINDOWPOSCHANGING(Var msg: TWMWINDOWPOSCHANGING);
var
r: TRect;
Begin
With msg.Windowpos^ Do Begin
If (flags and SWP_NOMOVE) = 0 Then Begin
Windows.GetClientrect( Application.Mainform.clienthandle, r );
If x < 0 then x:= 0;
if y < 0 then y:= 0;
if (x+cx) > r.right then x:= r.right - cx;
if (y+cy) > r.bottom then
y:= r.bottom - cy;
End;
End;
inherited;
End;

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Dirk Naudts

unread,
Oct 22, 2001, 3:50:21 AM10/22/01
to
Thanks Peter,

works lovely !
I used to do it this way :

procedure Tfrmnextlots.WndProc(var Message: Tmessage);
begin
// frmstrKlok is main MDI form
inherited;
if message.Msg = WM_MOVE then
begin
if left < 0 then
left := 0;
if Top < 0 then
Top := 0;
if left > (frmstrKlok.clientwidth - (width+5)) then
left := frmstrKlok.clientwidth - (width+5);
if top > frmstrKlok.clientheight - (height+60) then
top := frmstrKlok.clientheight - (height+60);
if Sys.autoupdateFormsettings then
Savepos;
end;
end;

But this produced flickering and for a (to me) unknown reason produces AV
from time to time.

But as said, your solution is MUCH better !
Peter Below (TeamB) <10011...@compuXXserve.com> schreef in berichtnieuws
VA.00007bb...@antispam.compuserve.com...

0 new messages