I did the same in a different way
:
Code: Select all
PROCEDURE SnapToCtrl ( cForm, cControl )
Local hWnd, nRowCtrl, nColCtrl, nHeightCtrl, nWidthCtrl, nColPointer, nRowPointer
IF !(IsWindowActive ( &cForm )) .OR. !(IsControlDefined ( &cControl , &cForm ))
RETURN
ENDIF
hWnd := GetProperty ( cForm, 'Handle' )
nRowCtrl := GetProperty ( cForm , cControl, 'Row' )
nColCtrl := GetProperty ( cForm , cControl, 'Col' )
nHeightCtrl := GetProperty ( cForm , cControl, 'Height' )
nWidthCtrl := GetProperty ( cForm , cControl, 'Width' )
//Center of control
nRowPointer := nRowCtrl + ( nHeightCtrl / 2)
nColPointer := nColCtrl + ( nWidthCtrl / 2)
HMG_SetCursorPos ( hWnd, nRowPointer, nColPointer )
DoMethod( cForm, cControl, "Setfocus" )
RETURN
It seems to me that your solution does not work properly in all cases. Try to change the size of the form (height) with the mouse, then call from menu "Test" item "Snap 2 Button" and you will see that the mouse pointer does not always move to the right position: