Here's the basic version.
This pile o crap did my head before i got it to work you better off with basic quick.
loco i saw you're using the the other getline that go back in text when you find end whisper. There's no need for it with this code because you'll have the start whisper 1st.
But you have to clear the room text when it grow over 240k.
- Code: Select all
Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Integer
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal umsg As Long, ByVal wparam As Long, lParam As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)
Const WM_USER = &H400
Const EM_GETLINECOUNT = &HBA
Const EM_LINEINDEX = &HBB
Const EM_EXLINEFROMCHAR = (WM_USER + 54)
Const EM_GETLINE = &HC4
' last_char_index
' parameters:
' in: ruchedit control HWND
' returns: index of last (empty) line
Function last_char_index(ByVal rich20 As Long) As Long
Dim index, Lines As Long
Do
If IsWindow(rich20) = 0 Then
' invalid window handle
last_char_index = -1
Exit Function
End If
Lines = SendMessage(rich20, EM_GETLINECOUNT, ByVal 0&, ByVal 0&)
index = SendMessage(rich20, EM_LINEINDEX, ByVal Lines - 1, ByVal 0&)
' loop till no change was changed between the 2 calls
Loop While (index = -1 Or Lines <> SendMessage(rich20, EM_GETLINECOUNT, ByVal 0&, ByVal 0&))
last_char_index = index
End Function
' get_next_line
' parameters:
' in: richedit control HWND
' in/out: bext index to get line from
' out: buffer for line text out
' in: buffer size
' returns: true if lines added and text retrived, false otherwise
Function get_next_line(ByVal rich20 As Long, ByRef last_index As Long, ByRef retstr As String) As Boolean
Dim index, line, next_index, retlen As Long
Dim text_buff As String
Dim text_buff_size As Integer
' last line char index
index = last_char_index(rich20)
' check if text was cleared or haven't changed
If (index <= last_index) Then
If (index < last_index) Then
' text was cleared
last_index = index
End If
get_next_line = False
Exit Function
End If
text_buff_size = 255
text_buff = Space(256)
Do
' last index point to the bext line we need read
line = SendMessage(rich20, EM_EXLINEFROMCHAR, ByVal 0&, ByVal last_index)
' set the dirst word of the buffer to it's size - 1
' to reserve one byte for null char
Call CopyMemory(ByVal text_buff, text_buff_size, LenB(text_buff_size))
retlen = SendMessage(rich20, EM_GETLINE, line, ByVal text_buff)
' get character index for the begining of next line
next_index = SendMessage(rich20, EM_LINEINDEX, line + 1, ByVal 0&)
' check if text was cleared
' without this we may loop forever
If (last_char_index(rich20) < index) Then
' part of the room text was cleared
' you may add code here to set last_index to point few lines back
get_next_line = False
Exit Function
End If
' keep looping if last_index's line changed
Loop While (line <> SendMessage(rich20, EM_EXLINEFROMCHAR, ByVal 0&, ByVal last_index))
' the buffer returned is not null terminated unless there's no text
' sset the null terminator anyway
If (retlen > 0) Then
retstr = Left(text_buff, retlen)
Else
retstr = ""
End If
last_index = next_index
get_next_line = True
End Function





