1. Center Window Based On Parent Window
- Posted by "Chris B" <exceptionalgreatness at hotmail.com> Apr 22, 2004
- 665 views
Hello All, I am trying to center a window based on the position of the parent window. So the newly opened window will always be in the center of the parent window. I know how to center a window, but I am having problems with this, anyone has a solution? Thanks in advance, Chris
2. Re: Center Window Based On Parent Window
- Posted by rangi <totorangi at hotmail.com> Apr 22, 2004
- 580 views
Here's the code I use - probably pinched from somewhere else. Just call proc with parameter as name of window to be centered. Note that it assumes WinMain is your parent. -- Position a window in the centre of the screen procedure CentreWin(atom win_id) sequence winloc -- position of main window on screen x, y , x1, y1 sequence loc -- position of window to be centred atom xsize,ysize winloc=getRect(WinMain) -- get position of main window loc=getRect(win_id) -- get dimensions of window to be centred xsize=loc[3]-loc[1] ysize=loc[4]-loc[2] setRect(win_id,floor(((winloc[3]+winloc[1])/2)-(xsize/2)),floor(((winloc[4]+winloc[2])/2)-(ysize/2)),xsize,ysize,1 ) -- move window to centre end procedure
3. Re: Center Window Based On Parent Window
- Posted by "Juergen Luethje" <j.lue at gmx.de> Apr 22, 2004
- 605 views
Christopher B wrote: > Hello All, > > I am trying to center a window based on the position of the parent window. > So the newly opened window will always be in the center of the parent > window. I know how to center a window, but I am having problems with this, > anyone has a solution?
global function centerX (integer parentX, integer parentWidth, integer childWidth) return parentX + (parentWidth-childWidth)/2 end function global function centerY (integer parentY, integer parentHeight, integer childHeight) return parentY + (parentHeight-childHeight)/2 end function -- Demo integer parentX, parentY, parentWidth, parentHeight, childWidth, childHeight integer childX, childY parentX = 100 parentY = 20 parentWidth = 80 parentHeight = 40 childWidth = 60 childHeight = 30 childX = centerX(parentX, parentWidth, childWidth) childY = centerY(parentY, parentHeight, childHeight) printf(1, "Upper left corner of the child window is {%d,%d}.", {childX,childY})
Regards, Juergen -- /"\ ASCII ribbon campain | |\ _,,,---,,_ \ / against HTML in | /,`.-'`' -. ;-;;,_ X e-mail and news, | |,4- ) )-,_..;\ ( `'-' / \ and unneeded MIME | '---''(_/--' `-'\_)
4. Re: Center Window Based On Parent Window
- Posted by Derek Parnell <ddparnell at bigpond.com> Apr 23, 2004
- 679 views
Using win32lib v.59.1 w = 600 h = 400 Win = create(Window, "title", 0, {0.25,-w/2}, {0.25,-h/2}, w, h, 0) Using win32lib v0.6 Win = create(Window, "title", 0, Center, Center, 600, 400, 0) -- Derek
5. Re: Center Window Based On Parent Window
- Posted by "Chris B" <exceptionalgreatness at hotmail.com> Apr 23, 2004
- 607 views
Thanks Derek and everyone else who responded! > > >posted by: Derek Parnell <ddparnell at bigpond.com> > >Using win32lib v.59.1 > > w = 600 > h = 400 > Win = create(Window, "title", 0, {0.25,-w/2}, {0.25,-h/2}, w, h, 0) > >Using win32lib v0.6 > > Win = create(Window, "title", 0, Center, Center, 600, 400, 0) > >-- >Derek > > > >For Topica's complete suite of email marketing solutions visit: >http://www.topica.com/?p=TEXFOOTER >