Somebody has used these functions?
The instructions do not work correctly.
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
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
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
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 ? :?
Could be if you didn't specify the form1 as the parent when creating it, etc.
Both versions of the code worked perfectly for me. I tested them both in FireFly before I posted them.