Location of a Mouse click on a PICTURE control?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
Red2
Posts: 273
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Location of a Mouse click on a PICTURE control?

Post 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
Red2
Posts: 273
Joined: Sat May 18, 2019 2:11 pm
DBs Used: Visual FoxPro, FoxPro
Location: United States of America

Re: Location of a Mouse click on a PICTURE control?

Post 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!
User avatar
gfilatov
Posts: 1068
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Contact:

Re: Location of a Mouse click on a PICTURE control?

Post 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. :arrow:

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
Attachments
TrackingToolTips.zip
(928.76 KiB) Downloaded 21 times
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein
User avatar
vagblad
Posts: 160
Joined: Tue Jun 18, 2013 12:18 pm
DBs Used: MySQL,DBF
Location: Thessaloniki, Greece

Re: Location of a Mouse click on a PICTURE control?

Post 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
Vagelis Prodromidis
Email: vagblad@gmail.com, Skype: vagblad
Post Reply