查看: 5  |  回复: 0
  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


您需要登录后才可以回帖 登录 | 立即注册
【本版规则】请勿发表违反国家法律的内容,否则会被冻结账号和删贴。
用户名: 立即注册
密码:
2020-2024 MaNongKu.com