'在form中放一个textbox两个label
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 hwnd5 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(hwnd5, em_getsel, wparam, lparam)
j = i / 2 ^ 16 '取得目前caret所在前面有多少个byte
lineno = sendmessage(hwnd5, em_linefromchar, j, 0) '取得前面有多少行
lineno = lineno + 1
k = sendmessage(hwnd5, em_lineindex, -1, 0)
'取得目前caret所在行前面有多少个byte
colno = j - k + 1
end sub
private sub form_load()
dim lineno as long, colno as long
call getcaretpos(text1.hwnd, lineno, colno)
label1.caption = lineno
label2.caption = colno
end sub
private sub text1_keyup(keycode as integer, shift as integer)
dim lineno as long, colno as long
call getcaretpos(text1.hwnd, lineno, colno)
label1.caption = lineno
label2.caption = colno
end sub
private sub text1_mousedown(button as integer, shift as integer, x as single, y as single)
dim lineno as long, colno as long
call getcaretpos(text1.hwnd, lineno, colno)
label1.caption = lineno
label2.caption = colno
end sub