none
vb2008怎样获得Textbox中光标的行列? RRS feed

  • 问题

  • vb6中我用这个方法实现了,可是在vb2008中不能用了:

    Const EM_GETSEL = &HB0
    Const EM_LINEFROMCHAR = &HC9
    Const EM_LINEINDEX = &HBB
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    Public Sub GetCaretPos(ByVal TextHwnd As Long, lineNo As Long, colNo As Long)
        Dim i As Long, j As Long
        Dim lParam As Long, wParam As Long
        Dim k As Long
        i = SendMessage(TextHwnd, EM_GETSEL, wParam, lParam)
        j = i / 2 ^ 16
        lineNo = SendMessage(TextHwnd, EM_LINEFROMCHAR, j, 0)
        lineNo = lineNo + 1
        k = SendMessage(TextHwnd, EM_LINEINDEX, -1, 0)
        colNo = j - k + 1
    End Sub

    2010年9月27日 6:14

答案

全部回复