Sathyadharan Posted September 3, 2012 Posted September 3, 2012 This app is meant to catch particular "chat line" which contains the few "string(s)" & beeps/flashes 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
MrCreatoR Posted September 3, 2012 Posted September 3, 2012 1. You are in the wrong section. 2. You should wrap the autoit code with corresponding tags ([ autoit ][/ autoit ]). Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team
Sathyadharan Posted September 3, 2012 Author Posted September 3, 2012 (edited) in which section should i post?.. thnx This app is meant to catch particular "chat line" which contains the few "string(s)" & beeps/flashes 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: ================ expandcollapse popupGlobal $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 Edited September 3, 2012 by Valik
Valik Posted September 3, 2012 Posted September 3, 2012 Wow, way to take the suggestion on using those tags so literal you just copy and pasted them including the spaces meaning they didn't do fuck all. Post preview any? Use it. Thread moved to the correct forum.
Sathyadharan Posted September 5, 2012 Author Posted September 5, 2012 Thnx Valik.. could u please also delete the same duplicate post in the same section... and.. i have noticed tht beep() causes a lag in the script for the mention milli seconds, which causes problem no.2 when text is added to the richedit box.. any ideas how to prevent script from lagging because of beep()?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now