Page 1 of 1
Location of a Mouse click on a PICTURE control?
Posted: Tue Feb 20, 2024 8:13 pm
by Red2
A FORM has a PICTURE Control.
This PICTURE Control's ACTION Event calls a Function.
When a mouse click happens on the PICTURE Control I need to save its location.
My Question:
How can this Function determine the click's row and column (on the PICTURE image)?
Thank you for your kind guidance here.
Red2
Re: Location of a Mouse click on a PICTURE control?
Posted: Tue Feb 20, 2024 11:58 pm
by Red2
Hello All,
I have been searching for some way to locate a mouse
click's location on a PICTURE control.
I found two possible candidates:
lnRow := _HMG_SYSDATA[ 191 ]
lnCol := _HMG_SYSDATA[ 192 ]
lnCursRow := GetCursorRow()
lnCursCol := GetCursorCol()
Unfortunately these values do not
directly indicate where the PICTURE was clicked.
Also I cannot find a definition of what they return.
These might be helpful in calculating the mouse click's location on the PICTURE.
Would someone more advanced point me to a definition?
Thanks again!
Re: Location of a Mouse click on a PICTURE control?
Posted: Wed Feb 21, 2024 8:40 am
by gfilatov
Red2 wrote: ↑Tue Feb 20, 2024 11:58 pm
Hello All,
I have been searching for some way to locate a mouse
click's location on a PICTURE control.
I found two possible candidates:
lnRow := _HMG_SYSDATA[ 191 ]
lnCol := _HMG_SYSDATA[ 192 ]
lnCursRow := GetCursorRow()
lnCursCol := GetCursorCol()
Unfortunately these values do not
directly indicate where the PICTURE was clicked.
Also I cannot find a definition of what they return.
These might be helpful in calculating the mouse click's location on the PICTURE.
Would someone more advanced point me to a definition?
Thanks again!
Hello Spencer,
Thanks for your interest.
You can find the source code for working example along with the executable in the attachment below.
But the above code is for use with MiniGUI Extended Edition.
Look at the following code snippet with a hint:
Code: Select all
FUNCTION Determine_The_Portion_Of_The_Picture( aPoint )
STATIC s_aImage := { { 0, 0, 200, 149 }, { 202, 0, 691, 149 }, { 693, 0, 933, 149 } }
LOCAL nArea
LOCAL cMsg := ""
IF ( nArea := Ascan( s_aImage, { |aRect| PtInRect( aPoint, aRect ) } ) ) > 0
cMsg += "Pos Y: " + hb_NtoS( aPoint[ 2 ] ) + "; "
cMsg += "Pos X: " + hb_NtoS( aPoint[ 1 ] )
cMsg += CRLF + CRLF + "Area #" + hb_NtoS( nArea )
cMsg += CRLF + "Part " + hb_NtoS( nArea ) + " of a picture."
ENDIF
RETURN cMsg
Re: Location of a Mouse click on a PICTURE control?
Posted: Wed Feb 21, 2024 9:51 am
by vagblad
Hello Red,
I'll add my own implementation of the matter at hand fo a similar situation(not exactly like the one you described)!!!It is definitely not as clean as the one that Grigory posted but i thought it might help someone.
So i wanted to hover over a control and then when i press a key combination to select that control.
Code: Select all
aCoords := GetCursorPos()
If !Empty(aCoords)
For i := 1 to len(aControls)
nMinX := aControls[i][6] + nFormCol//The column of the control + the column of the form
nMaxX := aControls[i][6] + aControls[i][4] + nFormCol //The last pixel of the control on X Axis(control's column + control's width)
nMinY := aControls[i][7] + nFormRow//The row of the control + the row of the form
nMaxY := aControls[i][7] + aControls[i][5] + nFormRow//The last pixel of the control on Y Axis(control's row + control's height)
If aCoords[1] >= nMinY .AND. aCoords[1] <= nMaxY //If the cursor is in between the limits of the Y axis
If aCoords[2] >= nMinX .AND. aCoords[2] <= nMaxX //If the cursor is also in between the limits of the X axis
If aControls[i][8] == .T. //If the control which is on the cursor is visible
AAdd(aMatchControls, aControls[i])
EndIf
EndIf
EndIf
Next i
EndIf
aControls is an array which includes the following elements:
Code: Select all
aControls[i][6] := GetProperty(cForm,cControl,"Col")
aControls[i][7] := GetProperty(cForm,cControl,"Row")
aControls[i][8] := GetProperty(cForm,cControl,"Visible")
You can replace the GetCursorPos() function with the ones you used:
lnCursRow := GetCursorRow()
lnCursCol := GetCursorCol()
So in the end you get an array with the name of the control,row,column etc. The control you've hovered over.
Hope it helps