Re: Restrining a child window's positioning within parent window

new topic     » goto parent     » topic index » view thread      » older message » newer message

> Subject: Re: Restrining a child window's positioning within 
> parent window
> 
> 
> posted by: don cole <doncole at pacbell.net>
> 
> Rad wrote:
> > 
> > Hi,
> > 
> > I have a Parent window containing many child windows.
> > 
> > I want to restrain any child window from being moved out of 
> parent window's
> > client area (using win32lib).
> > 
> > How can I do this?
> > 
> > Regards,
> > Rad.
> 
> Hello Rad,
> 
> I don't know exactly how to do this, but you would have to know,
> 
> The size of you main window.
> The size and location of all the children.
> I would try getChildren() along  with getSystemMetrics() to 
> monitor things.
> Then setRect() to make sure do not exceed you limits.
> 
> Don Cole
>  Bonds > Ruth.
>  Giants STILL in last place 
>  Hmmmmmmmm!

First of all, use addStyle(your_window,WS_CHILD), or, better, add this style
in the create[Ex] statement used to create it. 
I can't test it right now, but that should be the simplest way.

If the problem is preventing any portion of a child to be clipped out of the
main window, it means that you can move the child. Hook the move, and then
check if the child's client rect is inside the main client rect.

"Hooking the move" means setting up a routine which will monitor the
WM_MOVING message, then issuing 
setWinMsgHandler(my_window,WM_MOVING,routine_id("my_handler"))

my_handler will be called with a pointer to a rectangle as its lparam
argument. 
This is the rectangle of the moved window. Just peek4s and poke4 values
there to check and set the new position.
Offsets are: +0=left,+4=top,+8=right,+12=bottom.

CChris

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu