Centering a child window inside the parent's client area (None Specified)
At 27 JAN 1998 11:40:29AM David Pociu wrote:
As I'm working on the "niceties" of my current application, I'd like to be able to center certain child windows within the CLIENT part of the MDI parent window.
I know CLIENTSIZE gives me the width and height of the client area, but my problem is that I don't know where that area starts (upper left hand coordinates).
Since using the SIZE property to center a window requires absolute screen coordinates (I believe) I am at a loss as to how to do this centering without knowing the absolute coordinates of the upper left hand corner of the client area of the MDI window.
Can anyone give me some hints on this one? An example would be even more appreciated !
Thanks
At 27 JAN 1998 03:56PM Cameron Purdy wrote:
David,
I'd like to be able to center certain child windows within the CLIENT part of the MDI parent window. I know CLIENTSIZE gives me the width and height of the client area, but my problem is that I don't know where that area starts (upper left hand coordinates).
You could just calculate the position and use the (X,Y) parameters for Start_MDIChild:
Syntax mdichildID=Start_MDIChild(mdichildgroupID, mdiframeID, createparam, mdichildinstanceID, mdichildtitle, initialappearancemode , initx, inity, winStruct)The (X,Y) portion of the Size property of an MDI child is relative to the upper left hand corner of the MDI client area, so you shouldn't have to adjust anything.
BTW, look at the SIZE and CLIENTSIZE of the .MDICLIENT "control" of the MDI frame. (This is really easy to see in the debugger.)
Cameron Purdy
At 27 JAN 1998 04:12PM Blaise(Revelation) wrote:
Hi Dave,
I wrote I little routine that centers an MDIChild window with in an MDIFrame. What I did not test for is to see if the child is bigger than the parent. Just a heads up incase this will be an issue.
Anyhow, here is the code I wrote. Let me know how you get along.
-Blaise
**************************** declare subroutine Start_MDIChild, Set_Property wChild = "TEST" wParent="MDIP" **The child window to be started is initially set to not visible Start_MDIChild( wChild , wParent , '' , '' , '' , 1 ) **Get the parent of the window and then get the size parent =Get_Property( wChild , 'PARENT' ) parentSize=Get_Property( parent , 'SIZE' ) **Get the size of the child window childSize=Get_Property( wChild , 'SIZE' ) **Subtract the child width from the parent width and divide the difference by 2 **Set the offset from the left of the child window to the result iWidthDifference =parentSize - childSize iOffsetFromLeft =iWidthDifference / 2 **Subtract the child height from the parent height and divide the difference by 2 **Set the offset from the top of the child window to the result iHeightDifference=parentSize - childSize iOffsetFromtop =iHeightDifference / 2 **Set the size property of the child to make it centered and visible Set_Property( wChild , 'SIZE' , iOffsetFromLeft:@FM:iOffsetFromtop:@FM:childSize:@FM:childSize)
At 27 JAN 1998 05:13PM David Pociu wrote:
Hi Blaise,
Thanks for the code. I changed it a little bit do make it do what I wanted once I realized that the SIZE property for a child window does not refer to absolute coordinates, but rather to coordinates within the client area.
Because I need the window centered in the middle of the CLIENT area instead of:
size=get_property(ParentWindow , 'SIZE')
I used :
size=get_property(ParentWindow , "CLIENTSIZE");][size=0:@fm:0:@fm:size /* x=0 , y=0 */
I did this because SIZE returns the ENTIRE size of the ParentWindow and I only wanted the size of the MDI Client area.I then performed the centering calculations from here.
Thank you for your code. It was very helpful in trying to make me see what I was doing wrong.
Dave
At 27 JAN 1998 05:18PM David Pociu wrote:
Hi Cameron,
My problem was that I used Start_Window by mistake instead of Start_MDIChild. Therefore, SIZE had absolute coordinates for me.
Thanks
At 27 JAN 1998 05:26PM Blaise(Revelation) wrote:
Hey Dave,
In my code I have the line that gets the parent for the child and then goes on to get the parent's size. In other words I am getting the size for the MDIClient Window and not the actual MDI form. This is why I don't use the 'CLIENTSIZE' property.
But hey, whatever works..!
Good Luckā¦
-Blaise
At 27 JAN 1998 06:51PM David Pociu wrote:
Aha! Well, looks like I just learned something new!
You're right, thanks.
At 28 JAN 1998 09:16AM Blaise(Revelation) wrote:
Dave,
One more small bit of info for you. With this code it will center the window fine but it will leave the focus somewhere else. In other words the window you are centering will not be active. Place this line of code at the end to make it active.
Set_Property(wChild , "FOCUS" , 1)
Good Luck
-Blaise