1. Restrining a child window's positioning within parent window

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.

new topic     » topic index » view message » categorize

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

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!

new topic     » goto parent     » topic index » view message » categorize

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

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.

I have re-thought your question.

I don't really know what you are tring to do.

But it appears to me that you are trying to open a main Window with an
undetermined amount of children inside. If that's the case what I do is design
a main Window with three children that fit nicely. Put the info into the first
three children. Then with the message box ask More? YESSNO.

If yes then erase the first three chilren and add three more.
If the child you are looking for is on the screen then click no and the message
box goes away. I think this would be easier than trying to calculate the size of
an undetermined amout of children.

Don Cole
 Bonds > Ruth.
 Giants STILL in last place 
 Hmmmmmmmm!

new topic     » goto parent     » topic index » view message » categorize

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

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:
   The easiest way to do this is to use an MDI window
  as the parent window.

Bernie

My files in archive:
WMOTOR, XMOTOR, W32ENGIN, MIXEDLIB, EU_ENGIN, WIN32ERU, WIN32API 

Can be downloaded here:
http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan

new topic     » goto parent     » topic index » view message » categorize

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

don cole wrote:
> 
> I have re-thought your question.
> 
> I don't really know what you are tring to do.
> 

Ok, I have this Main Window where all the options of the application are
available through a Menu.

Each option when clicked, opens up a child window, in which I
display/accept/process all the required details.

My problem is, once activated, user can move these Child Windows off the screen
by moving them around.

I would like to restrict the movement of these child windows within the client
area of the main window, so they are movable but not outside the client area of
main window.

Is this possible?

Regards,
Rad.

new topic     » goto parent     » topic index » view message » categorize

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

Bernie Ryan wrote:
> 
>    The easiest way to do this is to use an MDI window
>   as the parent window.
> 

How to convert an existing parent window to MDI (or create MDI Window)?

Regards,
Rad.

new topic     » goto parent     » topic index » view message » categorize

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

Rad wrote:
> 
> don cole wrote:
> > 
> > I have re-thought your question.
> > 
> > I don't really know what you are tring to do.
> > 
> 
> Ok, I have this Main Window where all the options of the application are
> available
> through a Menu.
> 
> Each option when clicked, opens up a child window, in which I
> display/accept/process
> all the required details.
> 
> My problem is, once activated, user can move these Child Windows off the
> screen
> by moving them around.

 Why don't you tell your users not be doing that?

> 

> I would like to restrict the movement of these child windows within the client
> area of the main window, so they are movable but not outside the client area
> of main window.
> 
> Is this possible?
> 
> Regards,
> Rad.

Don Cole
 Bonds > Ruth.
 Giants STILL in last place 
 Hmmmmmmmm!

new topic     » goto parent     » topic index » view message » categorize

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

I you use:

global constant CWindow = createEx( Window, "CWindow", Window1, 425,0, 308,
240,{WS_CHILD, WS_THICKFRAME}, 0 )

Then users can't move the window.

Don Cole

new topic     » goto parent     » topic index » view message » categorize

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

Rad wrote:
> 
> I would like to restrict the movement of these child windows within the client
> area of the main window, so they are movable but not outside the client area
> of main window.

Try using {WS_SYSMENU, WS_CHILD, WS_CAPTION} this is not resizeable, moves with
the parent window and can be moved itself only within the parent.

or if you don't want to allow any movement use either
{WS_CHILD, WS_DLGFRAME} or {WS_CHILD, WS_BORDER}
the last 2 move with the parent window but are not resizable or moveable by
themselves.

Regards PeteS

new topic     » goto parent     » topic index » view message » categorize

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

> 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).

I think what you want is the WS_CLIPCHILDREN style. This prevents the
child windows from being moved outside the parent's client area.

include Win32Lib.ew
without warning

constant
  Main = create( Window, "Restrict Child Window Movement Demo", 0,
Default, Default, 640, 480, WS_CLIPCHILDREN ),
  Child1 = create( Window, "Child Window", Main, Default, Default,
320, 240, w32or_all({WS_CHILD,WS_VISIBLE}) )

WinMain( Main, Normal )


new topic     » goto parent     » topic index » view message » categorize

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

Greg Haberek wrote:
> 
> > 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).
> 
> I think what you want is the WS_CLIPCHILDREN style. This prevents the
> child windows from being moved outside the parent's client area.

The example below fully restricts the child window so that no part of it
goes beyond the parent's borders.
 
include Win32Lib.ew

without warning

constant
  Main = create( Window, "Restrict Child Window Movement Demo", 0,
                 Default, Default, 640, 480, WS_CLIPCHILDREN ),
  Child1 = create( Window, "Child Window", Main, Default, Default,
                 320, 240, w32or_all({WS_CHILD,WS_VISIBLE}) )

constant WM_MOVING = #0216

procedure Moving_Child1(integer self, integer event, sequence parms)
    sequence lPos
    sequence vPos

    -- Only interested in moving windows.
    if parms[1] != WM_MOVING then
        return
    end if

    -- Get parent client area and calc boundaries.
    vPos = getClientSize(Main)
    vPos[3] += vPos[1]
    vPos[4] += vPos[2]

    -- Get boundaries of the moving window
    lPos = peek4s({parms[3],4})

    -- Check that left, top, right and bottom edge is still inside
    -- the parent boundary, and if not recalc where the edges should be.
    if (lPos[1] < vPos[1]) then
        lPos[3] = vPos[1] + lPos[3] - lPos[1]
        lPos[1] = vPos[1]
    end if
    if (lPos[2] < vPos[2]) then
        lPos[4] = vPos[2] + lPos[4] - lPos[2]
        lPos[2] = vPos[2]
    end if
    if (lPos[3] > vPos[3]) then
        lPos[1] = vPos[3] - lPos[3] + lPos[1]
        lPos[3] = vPos[3]
    end if
    if (lPos[4] > vPos[4]) then
        lPos[2] = vPos[4] - lPos[4] + lPos[2]
        lPos[4] = vPos[4]
    end if

    -- Write back the new boundaries so Windows can reposition the window.
    poke4(parms[3], lPos)
end procedure

setHandler(Child1, w32HEvent, routine_id("Moving_Child1"))

WinMain( Main, Normal )


-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

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

Derek Parnell wrote:
> 
> The example below fully restricts the child window so that no part of it
> goes beyond the parent's borders.
>  

Thanks Derek, this is was I was looking for.
And thanks to all Euphorians for the help.

One more Q Derek.....

When child window is opened for first time, the top-left/right of client
rectangle is correctly used. But then one can drag the window over "Toolbar" (but
not over "Menu") at the top as well as over "Statusbar" at the bottom. If this a
win32lib issue of not excluding toolbar and statusbar (if present) from client
area of a window?

Regards,
Rad.

new topic     » goto parent     » topic index » view message » categorize

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

Rad wrote:
> When child window is opened for first time, the top-left/right of client
> rectangle
> is correctly used. But then one can drag the window over "Toolbar" (but not
> over "Menu") at the top as well as over "Statusbar" at the bottom. If this a
> win32lib issue of not excluding toolbar and statusbar (if present) from client
> area of a window?

Technically the status bar and tool bar are children of the window and are thus
inside the parent's client area. However, I can see your point.

All you need to do is take the height of these bars into consideration when
calculating the parent's boundaries...

include Win32Lib.ew

without warning

constant
  Main = create( Window, "Restrict Child Window Movement Demo", 0,
                 Default, Default, 640, 480, WS_CLIPCHILDREN ),
  SB = create(StatusBar, "", Main, 0, 0, 0, 0, 0),
  TB = create(ToolBar, "", Main, 0, 0, 40, 40, 0),
  Bnt1 = create(Button, "CLICK", TB, 4, 4, 50, 25, 0),
  Child1 = create( Window, "Child Window", Main, 0, 0,
                 320, 240, {WS_CHILD,WS_VISIBLE,WS_CAPTION,WS_SYSMENU} )

constant WM_MOVING = #0216
integer TBH
integer SBH
procedure Activate_Main(integer self, integer event, sequence parms)
    sequence lSB, lTB
    -- Force the screen to be fully rendered at startup time.
    repaintWindow(0)
    -- Calc height of statusbar and toolbar
    lSB = getRect(SB)
    SBH = lSB[4] - lSB[2] - 1
    lTB = getRect(TB)
    TBH = lTB[4] - lTB[2] - 1
end procedure

procedure Moving_Child1(integer self, integer event, sequence parms)
    sequence lPos
    sequence vPos

    -- Only interested in moving windows.
    if parms[1] != WM_MOVING then
        return
    end if

    -- Get parent client area and calc boundaries taking the
    -- status and tool bars into consideration.
    vPos = getClientSize(findParent(self))
    vPos[2] += TBH
    vPos[3] += vPos[1]
    vPos[4] += vPos[2] - TBH - SBH

    -- Get boundaries of the moving window
    lPos = peek4s({parms[3],4})

    -- Check that left, top, right and bottom edge is still inside
    -- the parent boundary, and if not recalc where the edges should be.
    if (lPos[1] < vPos[1]) then
        lPos[3] = vPos[1] + lPos[3] - lPos[1]
        lPos[1] = vPos[1]
    end if
    if (lPos[2] < vPos[2]) then
        lPos[4] = vPos[2] + lPos[4] - lPos[2]
        lPos[2] = vPos[2]
    end if
    if (lPos[3] > vPos[3]) then
        lPos[1] = vPos[3] - lPos[3] + lPos[1]
        lPos[3] = vPos[3]
    end if
    if (lPos[4] > vPos[4]) then
        lPos[2] = vPos[4] - lPos[4] + lPos[2]
        lPos[4] = vPos[4]
    end if

    -- Write back the new boundaries so Windows can reposition the window.
    poke4(parms[3], lPos)
end procedure

setHandler(Child1, w32HEvent, routine_id("Moving_Child1"))
setHandler(Main, w32HActivate, routine_id("Activate_Main"))

WinMain( Main, Normal )


-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

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

> 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 message » categorize

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

Derek, interesting example. On my computer if I drag the child window to the
very top of the parent window then down, the top of the child window is
somewhat destroyed and it's top is only several black lines. Is there a fix
for this? I'm using 59.1 if that might make any difference.

new topic     » goto parent     » topic index » view message » categorize

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

George Walters wrote:
> 
> Derek, interesting example. On my computer if I drag the child window to the
> very top of the parent window then down, the top of the child window is
> somewhat destroyed and it's top is only several black lines. Is there a fix
> for this? I'm using 59.1 if that might make any difference.

Don't know why that's happening. I'm using the latest win32lib on XP and it
works fine. Try repainting the child window.

-- 
Derek Parnell
Melbourne, Australia
Skype name: derek.j.parnell

new topic     » goto parent     » topic index » view message » categorize

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

Derek Parnell wrote:
> 
> Technically the status bar and tool bar are children of the window and are
> thus
> inside the parent's client area. However, I can see your point.
> 
> All you need to do is take the height of these bars into consideration when
> calculating the parent's boundaries...

Thanks Derek.

Got it working with your latest code.

Regsrds,
Rad.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu