取得光标所在的行和列 GetCurPos怎么用??
Option ExplicitPublic Const WM_USER = &H400
Public Const EM_EXGETSEL = WM_USER + 52
Public Const EM_LINEFROMCHAR = &HC9
Public Const EM_LINEINDEX = &HBB
Public Const EM_GETSEL = &HB0
Public Type CHARRANGE
cpMin As Long
cpMax As Long
End Type
Public Type POINTAPI
x As Long
y As Long
End Type
Public 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 Declare Sub CopyMemory Lib "kernel32" Alias _
"RtlMoveMemory" (pDst As Any, pSrc As Any, _
ByVal ByteLen As Long)
'取得光标所在的行和列
Public Function GetCurPos(ByRef TextControl As Control) As POINTAPI
Dim LineIndex As Long
Dim SelRange As CHARRANGE
Dim TempStr As String
Dim TempArray() As Byte
Dim CurRow As Long
Dim CurPos As POINTAPI
TempArray = StrConv(TextControl.Text, vbFromUnicode)
'取得当前被选中文本的位置 适用于 RichTextBox
'TextControl 用 EM_GETSEL 消息
Call SendMessage(TextControl.hWnd, EM_EXGETSEL, 0, SelRange)
'根据参数wParam指定的字符位置返回该字符所在的行号
CurRow = SendMessage(TextControl.hWnd, EM_LINEFROMCHAR, SelRange.cpMin, 0)
'取得指定行第一个字符的位置
LineIndex = SendMessage(TextControl.hWnd, EM_LINEINDEX, CurRow, 0)
If SelRange.cpMin = LineIndex Then
GetCurPos.x = 1
Else
TempStr = String(SelRange.cpMin - LineIndex, 13)
'复制当前行开始到选择文本开始的文本
CopyMemory ByVal StrPtr(TempStr), ByVal StrPtr(TempArray) + LineIndex, SelRange.cpMin - LineIndex
TempArray = TempStr
'删除无用的信息
ReDim Preserve TempArray(SelRange.cpMin - LineIndex - 1)
'转换为 Unicode
TempStr = StrConv(TempArray, vbUnicode)
GetCurPos.x = Len(TempStr) + 1
End If
GetCurPos.y = CurRow + 1
End Function
text1.text 取得光标所在的行和列 GetCurPos怎么用??
代码怎么写 来实现 显示 text1.text 取得光标所在的行和列????? --------------------编程问答-------------------- 追问:
当txt1.text读取 276 KB (282,804 字节) txt文件后!!!很多网上代码 都读取不准确(取得不了光标所在的行和列)!!寻求解决办法!!
以上代码是否能解决 大文件txt内容 取得光标所在的行和列??
麻烦高手指点1,2!!!谢谢 --------------------编程问答-------------------- 有没有 人知道啊???? --------------------编程问答-------------------- 用richtextbox --------------------编程问答--------------------
你说的光标是指什么?
看看 .SelStart 属性。
补充:VB , API