How to minimize lines lose while retriving room text

You can talk about VB programming here

How to minimize lines lose while retriving room text

Postby Chike » Mon Jan 21, 2008 2:41 pm


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
Image
Chike
imFiles Master
imFiles Master
 
Posts: 583
Joined: Sun May 13, 2007 6:20 pm

Re: How to minimize lines lose while retriving room text

Postby locohacker » Mon Jan 21, 2008 3:34 pm

Yeps I use getline to find out who send the whisper, will this code help with that, thas the problem I had with it cause I think i needed two do tripple the work to get the whisper sender nick :roll:
User avatar
locohacker
Site Admin
Site Admin
 
Posts: 4363
Joined: Fri Dec 31, 2004 6:59 pm

Re: How to minimize lines lose while retriving room text

Postby Chike » Mon Jan 21, 2008 3:51 pm

This code read the next line that haven't been read. For a whisper you'll get the name line 1st, start whisper, the whisper lines, and end whisper. You don't need to go back, just remember the whisper started and who's the user.
I don't know if it's possible that you will get a part of a whisper, but to be safe make whisper status global in case you cought it in the middle of posting.
Image
Chike
imFiles Master
imFiles Master
 
Posts: 583
Joined: Sun May 13, 2007 6:20 pm

Re: How to minimize lines lose while retriving room text

Postby Departure » Mon Jan 21, 2008 9:32 pm

I really think hooking is the way to go for theses greeters ect.. I look at hooking in vb6 but found it not as as easy as other languages, never the less i did find source code to hook controls in vb6 plus some examples, the source code i found can be used as dll or a user control that you just add to your form, very easy to use... illl post it later for you loco then you can hook the messages from richedit20a.
User avatar
Departure
Global Moderator
Global Moderator
 
Posts: 996
Joined: Thu Mar 17, 2005 11:26 am
Location: Australia

Re: How to minimize lines lose while retriving room text

Postby Chike » Tue Jan 22, 2008 8:41 am

Departure wrote:I really think hooking is the way to go for theses greeters ect..

Hooks for this kind of task :? definitely an overkill.
The only advantage hooks has over subclassing is the easy way to make them run in another process, and they must be in a DLL to be system wide hooks.
The rest, comunicating with your process remain the same, and their disadvantages are many, and shadow over this one particular advantage.
Image
Chike
imFiles Master
imFiles Master
 
Posts: 583
Joined: Sun May 13, 2007 6:20 pm


Return to Visual Basic Programming

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 0 guests