Results 1 to 3 of 3
  1. #1
    Star Lounger
    Join Date
    Feb 2001
    Location
    Virginia Beach, Virginia, USA
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mouse Position and Hover (Excel XP)

    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

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Mouse Position and Hover (Excel XP)

    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

  3. #3
    Star Lounger
    Join Date
    Feb 2001
    Location
    Virginia Beach, Virginia, USA
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mouse Position and Hover (Excel XP)

    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....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •