Sign in to follow this  
Followers 0
Sathyadharan

RichEdit coloring & hang-up problems

1 post in this topic

This app is meant to catch particular "chat line" which contains the few "string(s)" & beeps/flashes once found!

Everything was working fine when i used native edit box. But i wanted to highlight the "chat line" containing the string. So started using richedit control. (few functions were used from the posted forums here.. thnx to them all)

When using the richedit control, i started having few bugs

1. I have to use 3 @CRLF to enter a "blank line" between two lines, except at one place where i need just 2 @CRLF. I duno y.

2. "Randomly" sometimes the Richedit control hangs for a moment. At tht time, "no blank lines" are entered in the richedit between two lines. Samething happens when i hold the vertical or horizontal scroll bar for a while (intentionally preventing the update of richedit) & release it.

3. After working on other windows/apps for a while, and when i shift the focus back to this app, i see tht the whole background color of the richedit control becomes grey & i cannot see any text entered into the control till 1. a new line is entered into richedit programmatically or 2. manually selecting whole of the text of richedit.

4. When i mouse click the richedit control anywhere else except at the default - last character position of the last line ==> the next new line is colored black. This happens only for tht single new line, after tht i see the code running smoothly.

5. "Randomly" sometimes this part of the code malfunctions

for $j=UBound($exploded)-1 to 0 step -1
    if stringinstr($exploded[$j], $oldlasttext)>0 Then
ExitLoop
    EndIf
next

causing $j=-1 at the end of the loop.!!!

Need help.. i tried my best..

thnx

code below:

Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
opt("WinTitleMatchMode",2)
opt("TrayMenuMode",1)
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <Guiedit.au3>
#include <GuiRichEdit.au3>
#include <String.au3>
$frmCatcher = GUICreate("text Catcher", 626, 439, 187, 124)
GUISetBkColor("0x9932cc",$frmCatcher)
$editBox=_GUICtrlRichEdit_Create($frmCatcher,"", 8, 72, 609, 361,BitOR($ES_MULTILINE, $WS_HSCROLL, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
_GUICtrlRichEdit_SetBkColor($editBox, 0x000099)
_GUICtrlRichEdit_SetLimitOnText($editbox,10000000000)
GUICtrlSetCursor($editbox,16)   ; <==== not hiding the cursor in editbox
$lstWords = GUICtrlCreateList("", 296, 8, 97, 58)
$cmdAdd = GUICtrlCreateButton("ADD", 232, 8, 57, 25)
$cmdDel = GUICtrlCreateButton("DELETE", 232, 40, 57, 25)
$cmdCatch = GUICtrlCreateButton("CATCH", 88, 40, 65, 25)
$txtWord = GUICtrlCreateInput("", 88, 8, 137, 21)
$Label1 = GUICtrlCreateLabel("Text to Catch:", 8, 8, 71, 17)
$cmdStop = GUICtrlCreateButton("STOP", 160, 40, 65, 25)
GUICtrlSetState($cmdStop, $GUI_DISABLE)
$chkBeep = GUICtrlCreateCheckbox("Beep", 16, 32, 49, 17)
GUICtrlSetState($chkBeep, $GUI_CHECKED)
$chkFlash = GUICtrlCreateCheckbox("Flash", 16, 48, 49, 17)
;GUICtrlSetState($chkFlash, $GUI_CHECKED)
$chkShowAll = GUICtrlCreateCheckbox("Show All", 400, 48, 73, 17)
GUICtrlSetState($chkShowAll, $GUI_CHECKED)
$chkSaveLog = GUICtrlCreateCheckbox("Save Log", 400, 8, 73, 17)
GUICtrlSetState($chkSaveLog, $GUI_CHECKED)
$Start = 0
$i=0
$oldfirsttext = ""
$oldlasttext = ""
$fhandle = FileOpen("lists.txt",0)
If $fhandle = -1 Then
$fhandle = Fileopen("lists.txt",2)
    ;MsgBox(0, "Error", "Unable to open file.")
    ;Exit
EndIf
while 1
$line = filereadline($fhandle)
if @error = -1 then ExitLoop
GUICtrlSetData($lstWords,$line)
wend
fileclose($fhandle)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
Case $GUI_EVENT_CLOSE
    $count = _GUICtrlListBox_GetCount($lstWords)
    $fhandle = FileOpen("lists.txt",2)
    for $i=0 to $count-1
FileWriteLine($fhandle,_GUICtrlListBox_GetText($lstWords,$i))
    next
    FileClose($fhandle)
    $fhdata = _GUICtrlRichEdit_GetText($editbox,TRUE)
    if $fhdata <> "" then
$fname = "Catch" & @mday & @mon & @year & @hour & @min & @sec & ".txt"
$fhbackup = FileOpen($fname,2)
FileWrite($fhbackup,$fhdata)
FileClose($fhbackup)
    endif
    _GUICtrlRichEdit_Destroy($editbox)
    ExitLoop
Case $cmdAdd
    $text = GUICtrlRead($txtWord)
    if $text <> "" Then
GUICtrlSetData($lstWords,$text)
    endif
case $lstWords
    $index = _GUICtrlListBox_GetCaretIndex($lstWords)
    $text = _GUICtrlListBox_GetText($lstWords,$index)
    GUICtrlSetData($txtWord,$text)
case $cmdDel
    $index = _GUICtrlListBox_GetCaretIndex($lstWords)
    if $index <> -1 Then
_GUICtrlListBox_DeleteString($lstWords,$index)
    EndIf
case $cmdStop
    $Start = 0
    GUICtrlSetState($cmdStop, $GUI_DISABLE)
    GUICtrlSetState($cmdCatch, $GUI_ENABLE)
case $cmdCatch
    $Start = 1
    GUICtrlSetState($cmdCatch, $GUI_DISABLE)
    GUICtrlSetState($cmdStop, $GUI_ENABLE)
case Else
    $count = _GUICtrlListBox_GetCount($lstWords)
    if $count <> 0 and $start=1 and WinExists("--") Then
Local $items[$count]
for $n=0 to $count-1
$items[$n] = _GUICtrlListBox_GetText($lstWords,$n)
next

$oIE=_IEAttach ("--","embedded",2)
$text = _IEBodyReadTEXT($oIE)
$exploded = _StringExplode($text, chr(10))
$newfirsttext = $exploded[0]
$newlasttext = $exploded[UBound($exploded)-1]
if $oldfirsttext <> $newfirsttext or $oldlasttext <> $newlasttext Then
if $oldfirsttext = "" and $oldlasttext = "" Then
for $i = 1 to Ubound($exploded)-1
    for $j = 0 to $n-1
if stringInstr($exploded[$i], $items[$j])>0 then
_ADD_Line($editbox,$exploded[$i] & @CRLF & @CRLF & @CRLF ,"0x00ffff")
         _GUICtrlRichEdit_ScrollLines($editbox, 1)
if GUICtrlRead($chkBeep)= $GUI_CHECKED then
Beep(500,250)
endif
if GUICtrlRead($chkFlash)= $GUI_CHECKED then
WinFlash("text Catcher","",2)
EndIf
ExitLoop
EndIf
    Next
    if GUICtrlRead($chkShowAll) = $GUI_Checked and $j=$n then   
_ADD_Line($editbox,$exploded[$i] & @CRLF & @CRLF & @CRLF ,"0xffffff")
             _GUICtrlRichEdit_ScrollLines($editbox, 1)
            Else
             _ADD_Line($editbox,$exploded[$i]& @CRLF & @CRLF,"0xffffff")
             _GUICtrlRichEdit_ScrollLines($editbox, 1)
    endif
next
Else
for $j=UBound($exploded)-1 to 0 step -1
    if stringinstr($exploded[$j], $oldlasttext)>0 Then
ExitLoop
    EndIf
next
     if ubound($exploded-1)-$j <20 then
for $k = $j+1 to ubound($exploded)-1
    for $i = 0 to $n-1
if stringInstr($exploded[$k], $items[$i])>0 then
_GuiCtrlRichEdit_Deselect($editbox)
_ADD_Line($editbox,$exploded[$k] & @CRLF & @CRLF,"0x00ffff")
         _GUICtrlRichEdit_ScrollLines($editbox, 1)
if GUICtrlRead($chkBeep)= $GUI_CHECKED then
Beep(500,250)
endif
if GUICtrlRead($chkFlash)= $GUI_CHECKED then
WinFlash("text Catcher","",2)
EndIf
ExitLoop
EndIf
    next
    if GUICtrlRead($chkShowAll) = $GUI_Checked and $i=$n then
_GuiCtrlRichEdit_Deselect($editbox)
_ADD_Line($editbox,$exploded[$k] & @CRLF & @CRLF,"0xffffff")
             _GUICtrlRichEdit_ScrollLines($editbox, 1)
    endif   
next
     endif
EndIf
endif
$oldfirsttext = $newfirsttext
$oldlasttext = $newlasttext
    EndIf
EndSwitch
WEnd

Func MyErrFunc($oMYError)
Endfunc

Func _GUICtrlRichEdit_SetCharColor_No_Selection($hWnd, $iColor)
If Not IsHWnd($hWnd) Then Return SetError(101, 0, False)
Local $tCharFormat = DllStructCreate($tagCHARFORMAT)
DllStructSetData($tCharFormat, 1, DllStructGetSize($tCharFormat))
DllStructSetData($tCharFormat, 3, $icolor)
DllStructSetData($tCharFormat, 2, $CFM_COLOR)
DllStructSetData($tCharFormat, 6, $iColor)

Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tCharFormat)) <> 0
EndFunc

Func _Add_Line($hWnd, $sMessage, $sColor)
_GUICtrlRichEdit_PauseRedraw($hWnd)
_GUICtrlRichEdit_SetCharColor_No_Selection($hWnd, $sColor)
_GUICtrlEdit_AppendText($hWnd, $sMessage)
_GUICtrlRichEdit_ScrollLines($hWnd, 1)
_GUICtrlRichEdit_ResumeRedraw($hWnd)
Return 1
EndFunc

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0