PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Marco Ruiz on August 03, 2005, 04:37:41 PM

Title: FF_Control_SetLoc and FF_Control_GetLoc
Post by: Marco Ruiz on August 03, 2005, 04:37:41 PM
Somebody has used these functions?

The instructions do not work correctly.
Title: FF_Control_SetLoc and FF_Control_GetLoc
Post by: Marco Ruiz on August 03, 2005, 05:21:08 PM
I explain.
I have a form ( form1 ) than call to another form ( form2 ) and I desire that he find his place to the left of the form's upper right corner ( form1 ). Using code following it does not work . What am I doing wrong?

Code :

Function FORM2_WM_CREATE ( _
                            hWndForm As Dword, _  ' handle of Form
                            ByVal UserData As Long _  'optional user defined Long value
                            ) As Long
                           
 Local x1 As Long, y1 As Long, w1 As Long, h1 As Long
 Local x2 As Long, y2 As Long, w2 As Long, h2 As Long
 
'  FF_Control_GetLoc(getParent(hWndForm),x1,y1)
 FF_Control_GetSize(getParent(hWndForm), w1, h1)
 FF_Control_GetSize(hWndForm, w2, h2)
 FF_Control_SetLoc(hWndForm,w1-w2,0)
 
End Function
Title: FF_Control_SetLoc and FF_Control_GetLoc
Post by: Roger Garstang on August 04, 2005, 12:12:02 AM
Never use them much, but I'd guess that they are meant for controls only otherwise he wouldn't have that in the name.  You may want to use the API for what you want:

SetWindowPos
MoveWindow
GetWindowRect
Title: FF_Control_SetLoc and FF_Control_GetLoc
Post by: TechSupport on August 04, 2005, 01:45:57 AM
Hi Marco,

You were close. :)  You can not use GetParent because that only works with child controls. Your Form is not a child form (it does not use the WS_CHILD style). It is an "owned" window (not a child window). You also needed to get the position of the parent form to use in the calculation. The following code will work.


'------------------------------------------------------------------------------------------------------------------------
Function FORM2_WM_CREATE ( _
                        hWndForm As Dword, _  ' handle of Form
                        ByVal UserData As Long _  'optional user defined Long value
                        ) As Long

Local x1 As Long, y1 As Long, w1 As Long, h1 As Long
Local x2 As Long, y2 As Long, w2 As Long, h2 As Long

Local hWndParent As Dword
hWndParent = GetWindow( hWndForm, %GW_OWNER )

FF_Control_GetSize( hWndParent, w1, h1)
FF_Control_GetSize(hWndForm, w2, h2)
FF_Control_GetLoc( hWndParent, x1, y1)
FF_Control_SetLoc( hWndForm, x1+w1-w2, y1)

End Function



The following alternative will also work:

Local hWndParent As Dword
hWndParent = GetWindow( hWndForm, %GW_OWNER )

Local rcParent As Rect
Local rcPopup  As Rect

GetWindowRect hWndParent, rcParent
GetWindowRect hWndForm, rcPopup

SetWindowPos hWndForm, 0, _
            rcParent.nRight - (rcPopup.nRight - rcPopup.nLeft), _
            rcParent.nTop, _
            0, 0, %SWP_NOSIZE
Title: FF_Control_SetLoc and FF_Control_GetLoc
Post by: Marco Ruiz on August 05, 2005, 02:47:11 PM
Thanks Roger and Paul for the answer.

Paul, I have tested out with the 2 codes. With the first code persist the problem that I mention . The second code is correct.
I forgot to make the comment of that the second form ( form2 ) is no modal. ¿ can this be the problem with the first code ? :?
Title: FF_Control_SetLoc and FF_Control_GetLoc
Post by: Roger Garstang on August 05, 2005, 09:41:52 PM
Could be if you didn't specify the form1 as the parent when creating it, etc.
Title: FF_Control_SetLoc and FF_Control_GetLoc
Post by: TechSupport on August 05, 2005, 10:17:53 PM
Both versions of the code worked perfectly for me. I tested them both in FireFly before I posted them.