调用 sendmessage 函数后的小问题
[attach]75836[/attach]程序代码:
Option Explicit Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long Private Const EM_GETLINE As Long = &HC4 Private Const EM_GETLINECOUNT As Long = &HBA Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal length As Long) Private Sub Form_Load() Dim n As Integer Text1.Text = vbNullString For n = 0 To 19 Text1.Text = Text1.Text & "这是第" & Str(n + 1) & "行,I like vb6 very much." & vbCrLf Next End Sub Private Sub GetLine_Click() Dim S As String Dim length As Integer length = 40 S = Space(length) CopyMemory ByVal S, length, 2 '传递前,S的前2个字节保存需获取字符串的长度 SendMessage Text1.hwnd, EM_GETLINE, 5, ByVal S '读取第六行的内容 Print S Print "chr(0)的位置是 ", InStr(S, Chr(0)) End Sub Private Sub LineCount_Click() Dim count As Long count = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, ByVal 0&) Print "一共", count - 1, "行" End Sub
像其他API函数GetcomputerName等,返回的字符串都是以chr(0)结尾的,是我弄错了吗?
[ 本帖最后由 茅十八 于 2014-5-7 15:35 编辑 ]