'获得光标位置(按字节计算,起如行和起始列均为0)
Private Function GetCurPos(ptPos As POINTAPI) As Long
Dim nLine As Long, nCol As Long
Call SendMessage(Me.Text1.hwnd, EM_GETSEL, 0, ptPos)
nLine = SendMessage(Me.Text1.hwnd, EM_LINEFROMCHAR, ptPos.x, ByVal 0&) '获得行号
nCol = ptPos.x - SendMessage(Me.Text1.hwnd, EM_LINEINDEX, -1, 0) '获得列号
GetCurPos = ptPos.x '光标位置(按字节计算)
ptPos.y = nLine
ptPos.x = nCol
End Function
'获得光标位置(按字符计算)
Private Function GetCurPosCh(ptPos As POINTAPI) As Long
Dim nLine As Long, nCol As Long
Dim ByteBuffer() As Byte
SendMessage Me.Text1.hwnd, EM_GETSEL, 0, ptPos
nLine = SendMessage(Me.Text1.hwnd, EM_LINEFROMCHAR, ptPos.x, ByVal 0&) '获得行号
nCol = ptPos.x - SendMessage(Me.Text1.hwnd, EM_LINEINDEX, -1, 0)
ReDim ByteBuffer(1024)
ByteBuffer(1) = 4
SendMessage Me.Text1.hwnd, EM_GETLINE, nLine, ByteBuffer(0)
ReDim Preserve ByteBuffer(nCol)
nCol = Len(StrConv(ByteBuffer, vbUnicode)) - 1 '获得列号
GetCurPosCh = Me.Text1.SelStart '光标位置(按字符计算)
ptPos.y = nLine + 1
ptPos.x = nCol + 1
Erase ByteBuffer
End Function
Call GetCurPosCh(ptPos)
GetTextInfo = " 第 " & ptPos.y & " 行 , 第 " & ptPos.x & " 列"
温馨提示:答案为网友推荐,仅供参考