手揣网教程:绿色安全纯净官方版,体验当今速度最快的浏览器!

取得TextBox某一行的字串

时间:2024/12/22作者:未知来源:手揣网教程人气:

[摘要]这是使用EM_GETLINE message来做,比较奇特的是lParam是指向一个字串所在的位置, 但是该字串传入时,前两个Byte要存该字串允许的最大长度。 '以下在Form需一个Te...
这是使用EM_GETLINE message来做,比较奇特的是lParam是指向一个字串所在的位置, 但是该字串传入时,前两个Byte要存该字串允许的最大长度。  
'以下在Form需一个TextBox,并设定MultiLine = True, 一个Command Button  
Private Sub Command1_Click()  
Dim str5 As String  
str5 = GetaLine(Text1,1)  '取得第二行的字串,以0为基底  
End Sub  

'以下在.Bas  
Option Explicit  
Const EM_GETLINE = &HC4  
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 Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As String  
Dim str5(255) As Byte '如果您的字串 > 255 byte请自行增加该Byte Array  
Dim str6 As String, i As Long  

str5(0) = 255 '字串的前两个Byte存该字串的最大长度  
str5(0) = 255  
i = SendMessage(Text1.hwnd, EM_GETLINE, ntx, str5(0))  
If i = 0 Then  
    GetaLine = ""  
Else  
    str6 = StrConv(str5, vbUnicode)  
    GetaLine = Left(str6, InStr(1, str6, Chr(0)) - 1)  
End If  
End Function  

关键词:取得TextBox某一行的字串




Copyright © 2012-2018 手揣网教程(http://www.shouchuai.com) .All Rights Reserved 网站地图 友情链接

免责声明:本站资源均来自互联网收集 如有侵犯到您利益的地方请及时联系管理删除,敬请见谅!

QQ:1006262270   邮箱:kfyvi376850063@126.com   手机版