Hi,
The functioning of FF_Control_SetLoc according to the FF description:
QuoteSets the location of the top left corner of the control, in pixels.
The location is relative to the upper-left corner of the client area in the parent window.
I noticed a different behaviour.
Just to show the problem, I have a main form and a child form.
The child form is created by calling
i = CHILD_Show(HWND_MAIN, %True) So the parent of child form is form MAIN.
The child form has a button. Pressing that button does:
Function CHILD_CMD1_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
Local x, y As Long
FF_Control_GetLoc( hWndForm, x, y )
FF_Control_SetLoc( hWndForm, x, y )
End FunctionThe GetLoc/SetLoc combination should basically do .. nothing. The form location is fetched and the form is relocated to the same position.
However, in reality the child form is moved.
What happens is this:
FF_Control_GetLoc( hWndForm, x, y ) fetches the position of the child form, relative to its parent form.
FF_Control_SetLoc( hWndForm, x, y ) should position the child form, also relative to its parent form.
But what I see is that the form is positioned relative to the desktop.
Therefore each time the button is clicked, the child form moves to the upper left hand corner of the desktop until it disappears off screen.
See the screenshots that show what happens after one button click.
Kind regards
Replacing FF_Control_GetLoc by its source code and removing the coordinates conversion to be relative to the parent does the job.
Like this:
Function TBSTOCKS_CMDSELALL_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
Local x, y As Long
Local rc As Rect
''FF_Control_GetLoc( hWndForm, x, y )
' Do a check to ensure that this is actually a window handle
If IsWindow(hWndForm) Then
' Get the dimensions of the window
Function = GetWindowRect( hWndForm, rc)
' Return the Left and Top values back from the function
x = rc.nLeft
y = rc.nTop
End If
FF_Control_SetLoc( hWndForm, x, y )
End Function
Now the child form does not move anymore.
Seems like the coordinates conversion is missing from FF_Control_SetLoc.
Kind regards
Nothing is missing. You are misusing a function designed to retrieve the relative position of a control with a form handle. A form is not a control.
Jose,
You know far more about this then me, so I am not going to argue.
But in that case, the function description in the FF function library should be adjusted.
Now it says:
* For
FF_Control_GetLoc :
QuoteGets the location of the top left corner of the control, in pixels.
The location is relative to the upper-left corner of the client area in the parent window.
hWndControl: Handle of Control or Form (e.g. HWND_FORM1_COMMAND1)
Returns: 0 if error, non-zero if successful
nLeft returns the left position of the window
nTop returns the top position of the window
* For
FF_Control_SetLoc :
QuoteSets the location of the top left corner of the control, in pixels.
The location is relative to the upper-left corner of the client area in the parent window.
hWndControl: Handle of Control or Form (e.g. HWND_FORM1_COMMAND1)
nLeft: Sets the left position of the window
nTop: Sets the top position of the window
So I hope you understand my confusion.
Even more, the source code of FF_Control_SetLoc seems to allow the use of a window/form handle:
Quote' Do a check to ensure that this is actually a window handle
If IsWindow(hWndControl) Then
' Set the positioning of the window
Function = SetWindowPos( hWndControl, 0, nLeft, nTop, 0, 0, _
%SWP_NOZORDER Or %SWP_NOSIZE )
End If
Are there other functions that you would recommend to use, Jose?
Kind regards
I would remove "or Form".
Even more, the source code of FF_Control_SetLoc seems to allow the use of a window/form handle:
It works because SetWindowPos can be used with child, popup and top level windows.
But FF_Control_GetLoc is designed to work correctly with child controls only.