首页 /编程语言和算法/VB6/ASP
 VB6 利用API的SendMessage获得Text1中第3行的数据
今天 17:19

新建From1(窗体),新建Text1(TextBox,MultiLine选True,ScrollBars选3),Command1(按钮CommandButton),代码:

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
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETLINE = &HC4

Private Sub Command1_Click()
    Dim str(256) As Byte
    str(1) = 1    '最大允许存放256个字符
    '获取总行数,结果显示在文本框txtLineCount中
    txtlineCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    '获取第3行的数据放在str中,转换为字符串后显示在文本框txtString中
    SendMessage Text1.hwnd, EM_GETLINE, 2, str(0)
    txtString = StrConv(str, vbUnicode)
    Debug.Print txtString
End Sub


 
全部回复(0)
首页 | 电脑版 |