• Mouse Position and Hover (Excel XP)

    • This topic has 3 replies, 2 voices, and was last updated 21 years ago.
    Author
    Topic
    #403840

    I need to know where the mouse is when the hover event is triggered. ( I have an Ink Picture control and want data to pop up if the mouse is over ink.) The x,y pair is not handed in as with the move event. I have things working by monitoring the move event and putting the x,y in hidden labels that that the hover event reads. Losses a lot on style points.
    Any function to get the mouse location? (I tried GetMouseMovePointsEX but something was lost in the translation…..)

    thanks
    David

    Viewing 0 reply threads
    Author
    Replies
    • #816945

      You can use the Windows GetCursorPos and SetCursorPos API functions to get or set the current mouse cursor coordinates. Sample code:

      Option Explicit

      Public Declare Function GetCursorPos Lib “user32” _
      (lpPoint As POINTAPI) As Long

      Public Declare Function SetCursorPos Lib “user32” _
      (ByVal x As Long, ByVal y As Long) As Long

      Type POINTAPI
      X_Pos As Long
      Y_Pos As Long
      End Type

      Sub GetCursorCoordinates()

      Dim PT As POINTAPI
      Dim strMsg As String

      ‘ Position returned as pixels – ex: 800 x 600 screen:
      ‘ x = 0 to 800, y = 0 to 600
      GetCursorPos PT

      ‘ Display the cursor position coordinates
      strMsg = “X Position is : ” & PT.X_Pos & vbCrLf & _
      “Y Position is : ” & PT.Y_Pos
      MsgBox strMsg, vbInformation, “Get Cursor Position”
      ‘ Debug.Print strMsg

      End Sub

      Sub SetCursorPosition(xPos As Long, yPos As Long)
      SetCursorPos xPos, yPos
      End Sub

      Note that the screen coordinates are always returned in pixels, so factors like the current screen resolution, etc., may need to be taken into account if using these coordinates for some type of calculation.

      HTH

      • #817344

        thanks. That worked.
        Combined with ScreenToClient and PixelToInkSpace everything lined up. No more work around

        Always amazed how I can never find things that should be rather obvious….

      • #817345

        thanks. That worked.
        Combined with ScreenToClient and PixelToInkSpace everything lined up. No more work around

        Always amazed how I can never find things that should be rather obvious….

    Viewing 0 reply threads
    Reply To: Mouse Position and Hover (Excel XP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: