Jun 14th, 2000, 09:19 PM
Use the GetCursorPos api to get the cursor pos.
(Watch out with the non-client area of the form(borders, caption bar))
Here is an example
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Timer1_Timer()
Dim CursorPos As POINTAPI
Dim lLeft As Long
Dim lTop As Long
'Store cursor pos in the pointapi struct
GetCursorPos CursorPos
lLeft = (Me.Left / Screen.TwipsPerPixelX)
'Calculate border thickness - (((Width - ScaleWidth) / 2) / Screen.TwipsPerPixelX)
lLeft = lLeft + (((Width - ScaleWidth) / 2) / Screen.TwipsPerPixelX)
lTop = (Me.Top / Screen.TwipsPerPixelY)
'Calculate caption height
'The height - (((Width - ScaleWidth) / 2) / Screen.TwipsPerPixelX)
'Minus the border thickness - (Height - ScaleHeight) / Screen.TwipsPerPixelY
lTop = lTop - (((Width - ScaleWidth) / 2) / Screen.TwipsPerPixelX) + (Height - ScaleHeight) / Screen.TwipsPerPixelY
Debug.Print "Screen Location: " & (CursorPos.X) * Screen.TwipsPerPixelX & ";" & (CursorPos.Y) * Screen.TwipsPerPixelY
Debug.Print "Form Location: " & (CursorPos.X - lLeft) * Screen.TwipsPerPixelX & ";" & (CursorPos.Y - lTop) * Screen.TwipsPerPixelY
'Debug.Print "Form Mousemove: " & X & ";" & Y
End Sub
Hope it helps,
(Watch out with the non-client area of the form(borders, caption bar))
Here is an example
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Sub Timer1_Timer()
Dim CursorPos As POINTAPI
Dim lLeft As Long
Dim lTop As Long
'Store cursor pos in the pointapi struct
GetCursorPos CursorPos
lLeft = (Me.Left / Screen.TwipsPerPixelX)
'Calculate border thickness - (((Width - ScaleWidth) / 2) / Screen.TwipsPerPixelX)
lLeft = lLeft + (((Width - ScaleWidth) / 2) / Screen.TwipsPerPixelX)
lTop = (Me.Top / Screen.TwipsPerPixelY)
'Calculate caption height
'The height - (((Width - ScaleWidth) / 2) / Screen.TwipsPerPixelX)
'Minus the border thickness - (Height - ScaleHeight) / Screen.TwipsPerPixelY
lTop = lTop - (((Width - ScaleWidth) / 2) / Screen.TwipsPerPixelX) + (Height - ScaleHeight) / Screen.TwipsPerPixelY
Debug.Print "Screen Location: " & (CursorPos.X) * Screen.TwipsPerPixelX & ";" & (CursorPos.Y) * Screen.TwipsPerPixelY
Debug.Print "Form Location: " & (CursorPos.X - lLeft) * Screen.TwipsPerPixelX & ";" & (CursorPos.Y - lTop) * Screen.TwipsPerPixelY
'Debug.Print "Form Mousemove: " & X & ";" & Y
End Sub
Hope it helps,