Page 1 of 1

snap (move) Cursor to Control

Posted: Sun Feb 28, 2021 10:47 pm
by AUGE_OHR
hi,

do you like Mouse Option "snap-to-button" :?:
it does move Cursor to Yes / No Button when appear

this Function do move Cursor and Focus to your Control

Code: Select all

   Snap2Ctrl("Form_1", "oScroll")
SNAP2CTL.ZIP
(806 Bytes) Downloaded 101 times
have fun
! Note : it does NOT move to "highlight" Option. it does move to "center" of Control

Re: snap (move) Cursor to Control

Posted: Mon Mar 01, 2021 12:54 pm
by salamandra
Hi Jimmy,

Thank you Very much for share with us!

Salamandra, Brazil

Re: snap (move) Cursor to Control

Posted: Mon Mar 01, 2021 1:29 pm
by edk
I did the same in a different way 8-) :

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:
BUTTON_3.7z
(3.22 KiB) Downloaded 103 times

Re: snap (move) Cursor to Control

Posted: Mon Mar 01, 2021 11:22 pm
by AUGE_OHR
hi,

i did not know HMG_SetCursorPos()

thx for Advice

Re: snap (move) Cursor to Control

Posted: Tue Mar 02, 2021 9:36 pm
by Claudio Ricardo
i did not know HMG_SetCursorPos()
I did not know that function either (and many others)
Is there any updated documentation that includes the new functions?
I use the one in the IDE help but it is incomplete as of today.

Thanks in advance.

Re: snap (move) Cursor to Control

Posted: Tue Mar 02, 2021 10:15 pm
by edk
This function is documented in the HMG references available in the IDE.
reference.png
reference.png (147.12 KiB) Viewed 1244 times