Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32.dll" _
(lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32.dll" _
(ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal MSG As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const EM_CHARFROMPOS = &HD7
Private Function MAKELONG(ByVal LowWord As Integer, ByVal HighWord As Integer) As Long
MAKELONG = (LowWord And &HFFFF&) Or (HighWord * &H10000)
End Function
Private Function HWORD(ByVal LongValue As Long) As Integer
HWORD = (LongValue And &HFFFF0000) \ &H10000
End Function
Private Function LWORD(ByVal LongValue As Long) As Integer
If (LongValue And &HFFFF&) > &H7FFF Then
LWORD = (LongValue And &HFFFF&) - &H10000
Else
LWORD = LongValue And &HFFFF&
End If
End Function
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dim lpPoint As POINTAPI, rc As Long
Call GetCursorPos(lpPoint)
Call ScreenToClient(Me.Text1.hWnd, lpPoint)
Me.Label5(0).Caption = lpPoint.x
Me.Label5(1).Caption = lpPoint.y
rc = SendMessage(Me.Text1.hWnd, EM_CHARFROMPOS, 0, MAKELONG(CInt(lpPoint.x), CInt(lpPoint.y)))
lpPoint.x = LWORD(rc) + 1
lpPoint.y = HWORD(rc) + 1
Me.Label2(0).Caption = lpPoint.x
Me.Label2(1).Caption = lpPoint.y
End Sub |