
Identifying Cursor Row/Col position...
Quote:
>I was wandering if anyone can advise me if there is an API, or another way,
>of identifying the Cursor Row/Col position. With this I don't meanthe Mouse
>cursor, but rather the text cursor in a TEXT boX (rtfTEXT).
Put the following declarations in the General Declarations section of a form:
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
Const EM_LINEFROMCHAR = &HC9
Const EM_LINEINDEX = &HBB
The following code puts the Row/Col position in a Label:
Dim lLine As Long, lIndex As Long
'Get the current line
lLine = SendMessage(text1.hwnd, EM_LINEFROMCHAR, -1, 0&)
Label1 = "Line: " & lLine + 1
'Get the character offset of the first position of the line.
lIndex = SendMessage(text1.hwnd, EM_LINEINDEX, -1, 0&)
'Calculate the position of the cursor on the line.
Label1 = Label1 & " Pos: " & (text1.SelStart - lIndex + 1)
Lee Weiner
weiner AT fuse DOT net
http://home.fuse.net/lweiner