Jump to content

Tail GUI Attempt - Trouble with hilighting


Recommended Posts

Hi all,

I'm trying to make an AutoIt version of BareTail to monitor my logs in real-time, but I can't quite get it working properly. I want to be able to go into the hilight menu, select a string and color and have the lines that have that string show with the color I chose. For some reason, all my hilights are gone after the first scroll through. I don't know why. It also takes a while to display all the hilights.

What am I missing? Is there a better/faster way to accomplish this?

I'm using Randallcs wonderful APITailRW.au3 for this, which I've attached. Thanks for the help!

#include "C:Documents and SettingstestuserDesktopBaretailAPITailRW.au3"
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <GuiRichEdit.au3>
#include <ScrollBarConstants.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <GuiComboBoxEx.au3>
#include <Misc.au3>
OnAutoItExitRegister("_Exit")
$copyLog = "Testlog2.txt"
$var1 = 0
$var2 = 0
Global $sTailReg = "HKCUSoftwareOptumAutoTail"
Global $iSelectFlag = False
Global $sFile = ""
Global $aRestore[100][4]
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
; Create image lists for the buttons
$hImage1 = _GUIImageList_Create(16, 16, 5, 3, 6)
_GUIImageList_AddIcon($hImage1, "C:Documents and SettingsjdubarMy DocumentsScriptsWonderTool_Iconsfolder_open.ico")
$hImage2 = _GUIImageList_Create(16, 16, 5, 3, 6)
_GUIImageList_AddIcon($hImage2, "C:Documents and SettingsjdubarMy DocumentsScripts_AllIconssrchui_23.ico")
$Form1 =  GUICreate("Advanced Log Viewer", 500, 500, -1, -1)
$hOpen =  GUICtrlCreateButton("Open", 0, 0, 70, 20)
   _GUICtrlButton_SetImageList($hOpen, $hImage1)
$hHilite =  GUICtrlCreateButton("Highlight", 71, 0, 70, 20)
   _GUICtrlButton_SetImageList($hHilite, $hImage2)
;~ $hEdit1 =  _GUICtrlRichEdit_Create($Form1, FileRead($log), 1, 21, 498, 478, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
$hEdit1 =  _GUICtrlRichEdit_Create($Form1, "", 1, 21, 498, 478, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
   GUICtrlSetBkColor($hEdit1, 0xFFFFFF)
;~ ; Highlight the text
;~ $iStart = 0
;~ Do
;~  $aResults = _GUICtrlRichEdit_FindTextInRange($hEdit1, $text, $iStart)
;~  If $aResults[0] <> -1 Then
;~   $iLine = _GUICtrlRichEdit_GetLineNumberFromCharPos($hEdit1, $aResults[0])
;~   $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($hEdit1, $iLine)
;~   $iLen = _GUICtrlRichEdit_GetLineLength($hEdit1, $iLine)
;~   _GUICtrlRichEdit_SetSel($hEdit1, $iFirst, $iFirst+$iLen)
;~   _GUICtrlRichEdit_SetCharBkColor($hEdit1, "304050")
;~   $iStart = $aResults[1]
;~  EndIf
;~ Until $aResults[0] = -1
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Select
  Case $nMsg = $GUI_EVENT_CLOSE
   _GUICtrlRichEdit_Destroy($hEdit1)
   Exit
  Case $nMsg = $hHilite
   _HiLiteGUI()
   _GUICtrlRichEdit_SetText($hEdit1, "")
   _OpenFile($hEdit1, $sFile)
  Case $nMsg = $hOpen
   $aFile = _WinAPI_GetOpenFileName("Open File Dialog", _
                        "Text File (*.txt;*.log)", ".", "", "", 1, _
                        $OFN_EXPLORER, 0, $Form1)
   If $aFile[0] = 0 Then
    $sError = _WinAPI_CommDlgExtendedError()
    MsgBox(0, "Error", $sError)
   ElseIf $aFile[1] <> "" Then
    $sFile = $aFile[1]&""&$aFile[2]
    _GUICtrlRichEdit_SetText($hEdit1, ""); Clear the screen before displaying a new log
    _OpenFile($hEdit1, $sFile)
   EndIf
EndSelect
    $var2 = FileGetSize($sFile)
    If $var2 <> $var1 Then
        ConsoleWrite("Read in " & $var2 - $var1 & " bytes" &  @CRLF)
        ConsoleWrite("New data" & @CRLF)
        $file = _FileOpenAPI($sFile)
        $read = _FileReadAPI($file, $var2 - $var1, $var1)
        _FileCloseAPI($file)
        ConsoleWrite($read & @CRLF)
        FileWrite($copyLog, $read)
  $iAllLen = _GUICtrlRichEdit_GetTextLength($hEdit1, True)
  $iLineLen = StringLen($read)
  $iNewStart = $iAllLen - $iLineLen
  ;_GUICtrlRichEdit_SetText($hEdit1, FileRead($sFile))
  _GUICtrlRichEdit_AppendText($hEdit1, $read)
  ; Was trying to hilight new text, but it doesn't seem to be working quite right
;~   For $s = 0 To UBound($aRestore) - 1
;~  If $aRestore[$s][3] = 1 Then $fCase = True
;~  If $aRestore[$s][3] = 0 Then $fCase = False
;~  If StringInStr($read, $aRestore[$s][0], $fCase) <> 0 Then
;~  $iLine = _GUICtrlRichEdit_GetLineNumberFromCharPos($hEdit1, $iAllLen+1)
;~  $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($hEdit1, $iLine)
;~  $iLen = _GUICtrlRichEdit_GetLineLength($hEdit1, $iLine)
;~  _GUICtrlRichEdit_SetSel($hEdit1, $iFirst, $iFirst+$iLen)
;~  _GUICtrlRichEdit_SetCharBkColor($hEdit1, $aRestore[$s][1])
;~  ExitLoop; After finding one string, exit the loop and search for more - no multiple strings per line
;~  EndIf
;~   Next
  _GUICtrlRichEdit_ScrollToCaret($hEdit1)
        $var1 = $var2
    EndIf
WEnd
Func _OpenFile($edit, $sPath)
Local $iStart = 0, $oCount = 0, $fCase = False
_GUICtrlRichEdit_SetText($edit, FileRead($sPath))
; Add in the extra colors to the image list that were previously saved to the registry
; Also add them to an array for easy access: [0] - text, [1] - COLORREF, [2] - Hex color, [3] - Match case 0/1
For $i = 1 To 100
  $var = RegEnumVal($sTailReg, $i)
  If @error <> 0 Then
   ExitLoop
  ElseIf StringInStr(RegRead($sTailReg, $var), "|") <> 0 Then
   $aData = StringSplit(RegRead($sTailReg, $var), "|")
   $sHexColor = Hex($aData[2], 6)
   $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
   $aRestore[$oCount][0] = $aData[1] ; Text
   $aRestore[$oCount][1] = $aData[2] ; COLORREF
   $aRestore[$oCount][2] = $sHexColor; Hex Color
   $aRestore[$oCount][3] = $aData[3] ; Match Case (0/1)
   $oCount += 1
  EndIf
Next
If $oCount > 0 Then ReDim $aRestore[$oCount][4]
; Highlight the text
If IsArray($aRestore) And $aRestore[0][0] <> "" Then
  For $s = 0 To UBound($aRestore) - 1
   Do
    If $aRestore[$s][3] = 1 Then $fCase = True
    If $aRestore[$s][3] = 0 Then $fCase = False
    $aResults = _GUICtrlRichEdit_FindTextInRange($edit, $aRestore[$s][0], $iStart, -1, $fCase)
    ConsoleWrite($aRestore[$s][0]&@CRLF)
    If $aResults[0] <> -1 Then
     $iLine = _GUICtrlRichEdit_GetLineNumberFromCharPos($edit, $aResults[0])
     $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($edit, $iLine)
     $iLen = _GUICtrlRichEdit_GetLineLength($edit, $iLine)
     _GUICtrlRichEdit_SetSel($edit, $iFirst, $iFirst+$iLen)
     _GUICtrlRichEdit_SetCharBkColor($edit, $aRestore[$s][1])
     $iStart = $aResults[1]
     ;ExitLoop; After finding one string, exit the loop and search for more - no multiple strings per line
    EndIf
   Until $aResults[0] = -1
   $iStart = 0
  Next
EndIf
EndFunc
Func _HiLiteGUI()
Local $Form2, $hImage3, $sCase, $xCount = 0
Local $aColors[5][2] = [["Red",255],["Green",65280],["Blue",16711680],["Yellow",65535],["Custom",16777215]]; Array containing colors and COLORREF numbers
; Create the Form
$Form2 =  GUICreate("Highlighting", 335, 380, Default, Default, BitOr($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), -1, $Form1)
$hList =  GUICtrlCreateListView("String", 12, 12, 306, 206)
    _GUICtrlListView_SetColumnWidth($hList, 0, 280)
$hAdd =  GUICtrlCreateButton("Add", 10, 222, 70, 25)
$hDel =  GUICtrlCreateButton("Delete", 90, 222, 70, 25)
    GUICtrlCreateLabel("Background Color:", 170, 222, 150, 20)
$hCombo = _GUICtrlComboBoxEx_Create($Form2, "", 170, 242, 128, 120, $CBS_DROPDOWNLIST)
$hCustom = GUICtrlCreateButton("", 299, 242, 22, 22, $BS_ICON)
    GUICtrlSetImage($hCustom, "C:Documents and SettingsjdubarMy DocumentsScripts_AllIconsmfc90u_17105.ico", -1)
    GUICtrlCreateLabel("String:", 10, 269, 150, 20)
$hString =  GUICtrlCreateInput("", 10, 289, 310, 20)
$hCase = GUICtrlCreateCheckbox("Match Case", 10, 315, 80, 20)
$hOk =  GUICtrlCreateButton("Ok", 240, 345, 80, 25)
; Create the image list with the default colors and grab the custom color from the default reg key
$hImage3 = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFF0000, 16, 16)); Red
    _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x00FF00, 16, 16)); Green
    _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 16, 16)); Blue
    _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFFFF00, 16, 16)); Yellow
If RegRead($sTailReg, "") = "" Then
  _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFFFFFF, 16, 16)); White
Else
  _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, RegRead($sTailReg, ""), 16, 16)); Custom
EndIf
; Add in the extra colors to the image list that were previously saved to the registry
; Also add them to an array for easy access: [0] - text, [1] - COLORREF, [2] - Hex color, [3] - Match case 0/1
For $i = 1 To 100
  $var = RegEnumVal($sTailReg, $i)
  If @error <> 0 Then
   ExitLoop
  ElseIf StringInStr(RegRead($sTailReg, $var), "|") <> 0 Then
   $aData = StringSplit(RegRead($sTailReg, $var), "|")
   $sHexColor = Hex($aData[2], 6)
   $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
   _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $sHexColor, 16, 16))
   $aRestore[$xCount][0] = $aData[1]
   $aRestore[$xCount][1] = $aData[2]
   $aRestore[$xCount][2] = $sHexColor
   $aRestore[$xCount][3] = $aData[3]
   $xCount += 1
  EndIf
Next
If $xCount > 0 Then ReDim $aRestore[$xCount][4]
;_ArrayDisplay($aRestore)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3)
_GUICtrlListView_SetImageList($hList, $hImage3, 1)
; Add the colors
For $y = 0 To 4
  _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03s", $aColors[$y][0]), $y, $y)
    Next
_GUICtrlComboBoxEx_SetCurSel($hCombo, 0); Set the default color selection - otherwise, it shows a blank entry
; Add the listview items
If $xCount > 0 Then
  For $i = 0 To UBound($aRestore)-1
   _GUICtrlListView_AddItem($hList, $aRestore[$i][0], $i+5)
  Next
EndIf
GUISetState(@SW_SHOW, $Form2)
While 1
  If $iSelectFlag Then
   $iSelectFlag = False
   $aItem = _GUICtrlListView_GetSelectedIndices($hList, True)
   If $aItem[0] > 0 Then
    ; Display the string
    GUICtrlSetData($hString, _GUICtrlListView_GetItemText($hList, $aItem[1]))
    ; Display the color
    Select
     Case $aRestore[$aItem[1]][2] = 0xFF0000; Red
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 0)
     Case $aRestore[$aItem[1]][2] = 0x00FF00; Green
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 1)
     Case $aRestore[$aItem[1]][2] = 0x0000FF; Blue
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 2)
     Case $aRestore[$aItem[1]][2] = 0xFFFF00; Yellow
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 3)
     Case Else
      _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $aRestore[$aItem[1]][2], 16, 16))
      _GUIImageList_Swap($hImage3, _GUIImageList_GetImageCount($hImage3)-1, 4)
      _GUIImageList_Remove($hImage3, _GUIImageList_GetImageCount($hImage3)-1)
      _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3)
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 4); Set the combo box to display 'Custom' with the new color chosen
      ;_GUICtrlListView_SetImageList($hList, $hImage3, 1)
      _GUICtrlComboBoxEx_SetItemImage($hCombo, 4, 4)
      RegWrite($sTailReg, "", "REG_SZ", $aRestore[$aItem[1]][2])
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 4)
    EndSelect
    ; Display the case check
    Select
     Case $aRestore[$aItem[1]][3] = 1
      GUICtrlSetState($hCase, $GUI_CHECKED)
     Case $aRestore[$aItem[1]][3] = 0
      GUICtrlSetState($hCase, $GUI_UNCHECKED)
    EndSelect
   Else
    GUICtrlSetData($hString, "")
    GUICtrlSetState($hCase, $GUI_UNCHECKED)
    _GUICtrlComboBoxEx_SetCurSel($hCombo, 0)
   EndIf
  EndIf
  ; If the combo box is clicked, check if the color has changed
  If _GUICtrlComboBoxEx_GetDroppedState($hCombo) Then
   $aItemC = _GUICtrlListView_GetSelectedIndices($hList, True)
   If $aItemC[0] > 0 Then
    Do
     Sleep(100)
    Until _GUICtrlComboBoxEx_GetDroppedState($hCombo) = False
    If $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1] <> $aRestore[$aItemC[1]][1] Then
     ConsoleWrite($aItemC[1]&@CRLF&RegRead($sTailReg, $aItemC[1])&@CRLF&$aRestore[$aItemC[1]][1]&@CRLF&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&@CRLF)
     RegWrite($sTailReg, $aItemC[1], "REG_SZ", StringReplace(RegRead($sTailReg, $aItemC[1]), "|"&$aRestore[$aItemC[1]][1]&"|", "|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|")); Update the registry
     _GUICtrlListView_SetItemImage($hList, $aItemC[1], _GUICtrlComboBoxEx_GetCurSel($hCombo)); Update the listview
     $aRestore[$aItemC[1]][1] = $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]; Update the array
     $sHexColor = Hex($aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1], 6)
     $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
     $aRestore[$aItemC[1]][2] = $sHexColor
    EndIf
   EndIf
  EndIf
  $hMsg = GUIGetMsg()
  Select
   Case $hMsg = $GUI_EVENT_CLOSE Or $hMsg = $hOk
    ExitLoop
   Case $hMsg = $hCase
    ; If the case box has been changed, edit the registry, too
    $aItemB = _GUICtrlListView_GetSelectedIndices($hList, True)
    If IsArray($aItemB) Then
     If $aItemB[0] > 0 Then
      If $aRestore[$aItemB[1]][3] = 1 And GUICtrlRead($hCase) = $GUI_UNCHECKED Then
       $sTmp = StringTrimRight(RegRead($sTailReg, $aItemB[1]), 1)
       $sTmp &= 0
       RegWrite($sTailReg, $aItemB[1], "REG_SZ", $sTmp)
       $aRestore[$aItemB[1]][3] = 0
      EndIf
      If $aRestore[$aItemB[1]][3] = 0 And GUICtrlRead($hCase) = $GUI_CHECKED Then
       $sTmp = StringTrimRight(RegRead($sTailReg, $aItemB[1]), 1)
       $sTmp &= 1
       RegWrite($sTailReg, $aItemB[1], "REG_SZ", $sTmp)
       $aRestore[$aItemB[1]][3] = 1
      EndIf
     EndIf
    EndIf
   Case $hMsg = $hDel
    $aSel = _GUICtrlListView_GetSelectedIndices($hList, True)
    If $aSel[0] > 0 Then
     _ArrayDelete($aRestore, $aSel[1])
     $xCount -= 1
     ReDim $aRestore[$xCount][4]
     $sText = _GUICtrlListView_GetItemText($hList, $aSel[1])
     $iCount = 0
     RegDelete($sTailReg)
     For $i = 0 To $xCount-1
      If RegRead($sTailReg, $i) <> "" Then RegDelete($sTailReg, $i)
      RegWrite($sTailReg, $i, "REG_SZ", $aRestore[$i][0]&"|"&$aRestore[$i][1]&"|"&$aRestore[$i][3])
     Next
     _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($hList))
    EndIf
   Case $hMsg = $hAdd
    $dupeFlag = False
    If GUICtrlRead($hString) <> "" Then
     For $y = 0 To _GUICtrlListView_GetItemCount($hList)-1
      If StringInStr(_GUICtrlListView_GetItemText($hList, $y), GUICtrlRead($hString)) <> 0 Then
       $dupeFlag = True
       ExitLoop
      EndIf
     Next
     If $dupeFlag Then
      MsgBox(64, "Duplicate", "This search criteria already exists.")
     Else
      $iIndex = _GUICtrlListView_AddItem($hList, GUICtrlRead($hString), _GUICtrlComboBoxEx_GetCurSel($hCombo))
      If GUICtrlRead($hCase) = $GUI_CHECKED Then $sCase = 1
      If GUICtrlRead($hCase) = $GUI_UNCHECKED Then $sCase = 0
      RegWrite($sTailReg, $iIndex, "REG_SZ", GUICtrlRead($hString)&"|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|"&$sCase)
      $sHexColor = Hex($aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1], 6)
      $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
      $xCount += 1
      ReDim $aRestore[$xCount][4]
      $aRestore[$xCount-1][0] = GUICtrlRead($hString)
      $aRestore[$xCount-1][1] = $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]
      $aRestore[$xCount-1][2] = $sHexColor
      $aRestore[$xCount-1][3] = $sCase
      ;_ArrayDisplay($aRestore, $xCount)
     EndIf
    Else
     MsgBox(64, "Error", "No string was entered. Please enter a string to highlight.")
    EndIf
   Case $hMsg = $hCustom
    $sColorRef = _ChooseColor(0, 255, 0, $Form1)
    If $sColorRef <> -1 Then
     $aColors[4][1] = $sColorRef
     $sHexColor = Hex($sColorRef, 6)
     $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
     ;MsgBox(0, "", [email="$sColorRef&@CRLF&$sHexColor"]$sColorRef&@CRLF&$sHexColor[/email])
     _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $sHexColor, 16, 16))
     _GUIImageList_Swap($hImage3, _GUIImageList_GetImageCount($hImage3)-1, 4)
     _GUIImageList_Remove($hImage3, _GUIImageList_GetImageCount($hImage3)-1)
     _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3)
     _GUICtrlComboBoxEx_SetCurSel($hCombo, 4); Set the combo box to display 'Custom' with the new color chosen
     ;_GUICtrlListView_SetImageList($hList, $hImage3, 1)
     _GUICtrlComboBoxEx_SetItemImage($hCombo, 4, 4)
     RegWrite($sTailReg, "", "REG_SZ", $sHexColor)
     $aItemC = _GUICtrlListView_GetSelectedIndices($hList, True)
     If $aItemC[0] > 0 Then
      _GUICtrlListView_ClickItem($hList, $aItemC[1])
      _GUICtrlListView_SetItemImage($hList, $aItemC[1], _GUICtrlComboBoxEx_GetCurSel($hCombo))
      RegWrite($sTailReg, $aItemC[1], "REG_SZ", StringReplace(RegRead($sTailReg, $aItemC[1]), "|"&$aRestore[$aItemC[1]][1]&"|", "|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|")); Update the registry
      $aRestore[$aItemC[1]][2] = $sHexColor
     EndIf
    EndIf
  EndSelect
WEnd
GUIDelete($Form2)
EndFunc
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $tNMHDR, $IdFrom, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$IdFrom = DllStructGetData($tNMHDR, "IdFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iCode
  Case $NM_CLICK
   $iSelectFlag = True
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func _Exit()
_GUICtrlRichEdit_Destroy($hEdit1)
EndFunc

APITailRW.zip

Edited by buymeapc
Link to comment
Share on other sites

Ok, perhaps a better question would be: How can I speed up the highlighting of the search criteria? Currently, if there's a large amount of items to be highlighted, the app will either hang or take a long time.

Link to comment
Share on other sites

Ok. Here's what I have so far since I've been working on this. Everything seems to work well, except that the hilighting is slow and if there are a lot of hilights to make, the script can choke. I'm assuming this is because of an array limitation (??). Can someone please help me make the hilighting work better on this? Thanks!

#include "C:\Documents and Settings\User\Desktop\Baretail\APITailRW.au3"
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiEdit.au3>
#include <GuiRichEdit.au3>
#include <ScrollBarConstants.au3>
#include <Array.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <GuiComboBoxEx.au3>
#include <StaticConstants.au3>
#include <GuiScrollBars.au3>
#include <Misc.au3>
OnAutoItExitRegister("_Exit")
Global $copyLog = "Testlog2.txt"
Global $var1 = 0
Global $var2 = 0
Global $sTailReg = "HKCU\Software\Test\Keywords"
Global $iSelectFlag = False
Global $sFile = ""
Global $aRestore[100][4], $aLines[1][2], $iLineCount = 0
Global $scrollFlag = False, $nMax = 0
Global $hEdit1, $hOpen, $hHilite, $hFollow, $hInput, $hEdit1
Global $Form1
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
_TailMain()
Func _TailMain()
; Create image lists for the buttons
$hImage1 = _GUIImageList_Create(16, 16, 5, 3, 6)
_GUIImageList_AddIcon($hImage1, "C:\Documents and Settings\User\My Documents\Scripts\folder_open.ico")
$hImage2 = _GUIImageList_Create(16, 16, 5, 3, 6)
_GUIImageList_AddIcon($hImage2, "C:\Documents and Settings\User\Scripts\_AllIcons\srchui_23.ico")
$Form1 =  GUICreate("Advanced Log Viewer", 700, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX))
$hOpen =  GUICtrlCreateButton("Open", 0, 0, 70, 20)
    _GUICtrlButton_SetImageList($hOpen, $hImage1)
$hHilite =  GUICtrlCreateButton("Highlight", 71, 0, 70, 20)
    _GUICtrlButton_SetImageList($hHilite, $hImage2)
$hFollow = GUICtrlCreateCheckbox("Follow Log", 147, 1, 70, 20)
    GUICtrlSetState(-1, $GUI_CHECKED)
$hInput = GUICtrlCreateLabel("", 224, 1, 475, 19, $SS_SUNKEN)
$hEdit1 =  _GUICtrlRichEdit_Create($Form1, "", 1, 21, 698, 478, BitOR($ES_MULTILINE, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
    _GUICtrlRichEdit_SetEventMask($hEdit1, BitOR($ENM_SCROLL, $ENM_SCROLLEVENTS))
    GUICtrlSetBkColor($hEdit1, 0xFFFFFF)
GUISetState(@SW_SHOW)
While 1
  $nMsg = GUIGetMsg()
  Select
   Case $nMsg = $GUI_EVENT_CLOSE
    _GUICtrlRichEdit_Destroy($hEdit1)
    Exit
   Case $nMsg = $hHilite
    _HiLiteGUI()
    If $sFile <> "" Then
     _GUICtrlRichEdit_SetText($hEdit1, "")
     _OpenFile($hEdit1, $sFile)
    EndIf
   Case $nMsg = $hOpen
    $aFile = _WinAPI_GetOpenFileName("Open File Dialog", _
       "Text File (*.txt;*.log)", ".", "", "", 1, _
       $OFN_EXPLORER, 0, $Form1)
    If $aFile[0] = 0 Then
     $sError = _WinAPI_CommDlgExtendedError()
     MsgBox(0, "Error", $sError)
    ElseIf $aFile[1] <> "" Then
     $sFile = $aFile[1]&"\"&$aFile[2]
     _GUICtrlRichEdit_SetText($hEdit1, ""); Clear the screen before displaying a new log
     GUICtrlSetData($hInput, $sFile)
     _OpenFile($hEdit1, $sFile)
     $var1 = FileGetSize($sFile)
    EndIf
   Case $nMsg = $hFollow
    If GUICtrlRead($hFollow) = $GUI_CHECKED And $scrollFlag = False Then
     $scrollFlag = True
     ConsoleWrite($nMax&@LF)
     $iNum = _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($hEdit1)
     $iNum = _GUICtrlRichEdit_GetLineCount($hEdit1) - $iNum
     _GUICtrlRichEdit_ScrollLines($hEdit1, $iNum)
     _GUICtrlRichEdit_ScrollLineOrPage($hEdit1, "lu")
    ElseIf GUICtrlRead($hFollow) = $GUI_UNCHECKED And $scrollFlag Then
     $scrollFlag = False
    EndIf
  EndSelect
  $var2 = FileGetSize($sFile)
  If $var2 <> $var1 Then
   ConsoleWrite("Read in " & $var2 - $var1 & " bytes" &  @CRLF)
   ConsoleWrite("New data" & @CRLF)
   $file = _FileOpenAPI($sFile)
   $read = _FileReadAPI($file, $var2 - $var1, $var1)
   _FileCloseAPI($file)
   ConsoleWrite($read & @CRLF)
   FileWrite($copyLog, $read)
   $iOldLines = _GUICtrlRichEdit_GetLineCount($hEdit1)
   _GUICtrlRichEdit_PauseRedraw($hEdit1)
   $iLineVisible = _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($hEdit1)
   _GUICtrlRichEdit_SetText($hEdit1, FileRead($sFile))
   $iNewLines = _GUICtrlRichEdit_GetLineCount($hEdit1)
   If $var1 <> 0 Then
    For $s = 0 To UBound($aRestore) - 1
     If $aRestore[$s][3] = 1 Then $fCase = True
     If $aRestore[$s][3] = 0 Then $fCase = False
     For $q = $iOldLines To $iNewLines
      If StringInStr(_GUICtrlRichEdit_GetTextInLine($hEdit1, $q), $aRestore[$s][0], $fCase) <> 0 Then
       ReDim $aLines[$iLineCount][2]
       $aLines[$iLineCount-1][0] = $q
       $aLines[$iLineCount-1][1] = $aRestore[$s][1]
       $iLineCount += 1
      EndIf
     Next
    Next
   EndIf
   For $l = 0 To UBound($aLines)-1
    $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($hEdit1, $aLines[$l][0])
    $iLen = _GUICtrlRichEdit_GetLineLength($hEdit1, $aLines[$l][0])
    _GUICtrlRichEdit_SetSel($hEdit1, $iFirst, $iFirst+$iLen, True)
    _GUICtrlRichEdit_SetCharBkColor($hEdit1, $aLines[$l][1])
   Next
   _GUICtrlRichEdit_ResumeRedraw($hEdit1)
   _GUICtrlRichEdit_Deselect($hEdit1)
   _GUICtrlRichEdit_SetSel($hEdit1, -1, -1, True)
   $nMax = _GUIScrollBars_GetScrollInfoMax($hEdit1, $SB_VERT)
   If GUICtrlRead($hFollow) = $GUI_CHECKED Then
    _GUICtrlRichEdit_ScrollToCaret($hEdit1)
   Else
    $iNewLineVisible = _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($hEdit1)
    _GUICtrlRichEdit_ScrollLines($hEdit1, $iLineVisible-$iNewLineVisible)
   EndIf
   $var1 = $var2
  EndIf
WEnd
EndFunc
Func _OpenFile($edit, $sPath)
Local $iStart = 0, $oCount = 0, $fCase = False, $aPos
Dim $aLines[1][2], $iLineCount = 0
_GUICtrlRichEdit_SetText($edit, FileRead($sPath))
; Add in the extra colors to the image list that were previously saved to the registry
; Also add them to an array for easy access: [0] - text, [1] - COLORREF, [2] - Hex color, [3] - Match case 0/1
For $i = 1 To 100
  $var = RegEnumVal($sTailReg, $i)
  If @error <> 0 Then
   ExitLoop
  ElseIf StringInStr(RegRead($sTailReg, $var), "|") <> 0 Then
   $aData = StringSplit(RegRead($sTailReg, $var), "|")
   $sHexColor = Hex($aData[2], 6)
   $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
   $aRestore[$oCount][0] = $aData[1] ; Text
   $aRestore[$oCount][1] = $aData[2] ; COLORREF
   $aRestore[$oCount][2] = $sHexColor; Hex Color
   $aRestore[$oCount][3] = $aData[3] ; Match Case (0/1)
   $oCount += 1
  EndIf
Next
If $oCount > 0 Then ReDim $aRestore[$oCount][4]
_GUICtrlRichEdit_PauseRedraw($edit)
; Highlight the text
If IsArray($aRestore) And $aRestore[0][0] <> "" Then
  For $s = 0 To UBound($aRestore) - 1
   Do
    If $aRestore[$s][3] = 1 Then $fCase = True
    If $aRestore[$s][3] = 0 Then $fCase = False
    $aResults = _GUICtrlRichEdit_FindTextInRange($edit, $aRestore[$s][0], $iStart, -1, $fCase)
    ;ConsoleWrite($aRestore[$s][0]&@CRLF)
    If $aResults[0] <> -1 Then
     $iLine = _GUICtrlRichEdit_GetLineNumberFromCharPos($edit, $aResults[0])
     $aLines[$iLineCount][0] = $iLine
     $aLines[$iLineCount][1] = $aRestore[$s][1]
     $iLineCount += 1
     ReDim $aLines[$iLineCount+1][2]
     $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($edit, $iLine)
     $iLen = _GUICtrlRichEdit_GetLineLength($edit, $iLine)
     _GUICtrlRichEdit_SetSel($edit, $iFirst, $iFirst+$iLen, True)
     _GUICtrlRichEdit_SetCharBkColor($edit, $aRestore[$s][1])
     $iStart = $aResults[1]
    EndIf
   Until $aResults[0] = -1
   $iStart = 0
  Next
EndIf
;~  ReDim $aLines[$iLineCount-1][2]
If $iLineCount > 1 Then ReDim $aLines[$iLineCount-1][2]
_GUICtrlRichEdit_Deselect($edit)
_GUICtrlRichEdit_SetSel($edit, -1, -1, True)
_GUICtrlRichEdit_ResumeRedraw($edit)
$nMax = _GUIScrollBars_GetScrollInfoMax($hEdit1, $SB_VERT)
EndFunc
Func _HiLiteGUI()
Local $Form2, $hImage3, $sCase, $xCount = 0
Local $aColors[5][2] = [["Red",255],["Green",65280],["Blue",16711680],["Yellow",65535],["Custom",16777215]]; Array containing colors and COLORREF numbers
; Create the Form
$Form2 =  GUICreate("Highlighting", 335, 380, Default, Default, BitOr($WS_CAPTION, $WS_POPUP, $WS_SYSMENU), -1, $Form1)
$hList =  GUICtrlCreateListView("String", 12, 12, 306, 206)
    _GUICtrlListView_SetColumnWidth($hList, 0, 280)
$hAdd =  GUICtrlCreateButton("Add", 10, 222, 70, 25)
$hDel =  GUICtrlCreateButton("Delete", 90, 222, 70, 25)
    GUICtrlCreateLabel("Background Color:", 170, 222, 150, 20)
$hCombo = _GUICtrlComboBoxEx_Create($Form2, "", 170, 242, 128, 120, $CBS_DROPDOWNLIST)
$hCustom = GUICtrlCreateButton("", 299, 242, 22, 22, $BS_ICON)
    GUICtrlSetImage($hCustom, "C:\Documents and Settings\jdubar\My Documents\Scripts\_AllIcons\mfc90u_17105.ico", -1)
    GUICtrlCreateLabel("String:", 10, 269, 150, 20)
$hString =  GUICtrlCreateInput("", 10, 289, 310, 20)
$hCase = GUICtrlCreateCheckbox("Match Case", 10, 315, 80, 20)
$hOk =  GUICtrlCreateButton("Ok", 240, 345, 80, 25)
; Create the image list with the default colors and grab the custom color from the default reg key
$hImage3 = _GUIImageList_Create(16, 16, 5, 3)
    _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFF0000, 16, 16)); Red
    _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x00FF00, 16, 16)); Green
    _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0x0000FF, 16, 16)); Blue
    _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFFFF00, 16, 16)); Yellow
If RegRead($sTailReg, "") = "" Then
  _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, 0xFFFFFF, 16, 16)); White
Else
  _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, RegRead($sTailReg, ""), 16, 16)); Custom
EndIf
; Add in the extra colors to the image list that were previously saved to the registry
; Also add them to an array for easy access: [0] - text, [1] - COLORREF, [2] - Hex color, [3] - Match case 0/1
For $i = 1 To 100
  $var = RegEnumVal($sTailReg, $i)
  If @error <> 0 Then
   ExitLoop
  ElseIf StringInStr(RegRead($sTailReg, $var), "|") <> 0 Then
   $aData = StringSplit(RegRead($sTailReg, $var), "|")
   $sHexColor = Hex($aData[2], 6)
   $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
   _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $sHexColor, 16, 16))
   $aRestore[$xCount][0] = $aData[1]
   $aRestore[$xCount][1] = $aData[2]
   $aRestore[$xCount][2] = $sHexColor
   $aRestore[$xCount][3] = $aData[3]
   $xCount += 1
  EndIf
Next
If $xCount > 0 Then ReDim $aRestore[$xCount][4]
;_ArrayDisplay($aRestore)
    _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3)
_GUICtrlListView_SetImageList($hList, $hImage3, 1)
; Add the colors
For $y = 0 To 4
  _GUICtrlComboBoxEx_AddString($hCombo, StringFormat("%03s", $aColors[$y][0]), $y, $y)
    Next
_GUICtrlComboBoxEx_SetCurSel($hCombo, 0); Set the default color selection - otherwise, it shows a blank entry
; Add the listview items
If $xCount > 0 Then
  For $i = 0 To UBound($aRestore)-1
   _GUICtrlListView_AddItem($hList, $aRestore[$i][0], $i+5)
  Next
EndIf
GUISetState(@SW_SHOW, $Form2)
While 1
  If $iSelectFlag Then
   $iSelectFlag = False
   $aItem = _GUICtrlListView_GetSelectedIndices($hList, True)
   If $aItem[0] > 0 Then
    ; Display the string
    GUICtrlSetData($hString, _GUICtrlListView_GetItemText($hList, $aItem[1]))
    ; Display the color
    Select
     Case $aRestore[$aItem[1]][2] = 0xFF0000; Red
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 0)
     Case $aRestore[$aItem[1]][2] = 0x00FF00; Green
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 1)
     Case $aRestore[$aItem[1]][2] = 0x0000FF; Blue
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 2)
     Case $aRestore[$aItem[1]][2] = 0xFFFF00; Yellow
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 3)
     Case Else
      _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $aRestore[$aItem[1]][2], 16, 16))
      _GUIImageList_Swap($hImage3, _GUIImageList_GetImageCount($hImage3)-1, 4)
      _GUIImageList_Remove($hImage3, _GUIImageList_GetImageCount($hImage3)-1)
      _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3)
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 4); Set the combo box to display 'Custom' with the new color chosen
      ;_GUICtrlListView_SetImageList($hList, $hImage3, 1)
      _GUICtrlComboBoxEx_SetItemImage($hCombo, 4, 4)
      RegWrite($sTailReg, "", "REG_SZ", $aRestore[$aItem[1]][2])
      _GUICtrlComboBoxEx_SetCurSel($hCombo, 4)
    EndSelect
    ; Display the case check
    Select
     Case $aRestore[$aItem[1]][3] = 1
      GUICtrlSetState($hCase, $GUI_CHECKED)
     Case $aRestore[$aItem[1]][3] = 0
      GUICtrlSetState($hCase, $GUI_UNCHECKED)
    EndSelect
   Else
    GUICtrlSetData($hString, "")
    GUICtrlSetState($hCase, $GUI_UNCHECKED)
    _GUICtrlComboBoxEx_SetCurSel($hCombo, 0)
   EndIf
  EndIf
  ; If the combo box is clicked, check if the color has changed
  If _GUICtrlComboBoxEx_GetDroppedState($hCombo) Then
   $aItemC = _GUICtrlListView_GetSelectedIndices($hList, True)
   If $aItemC[0] > 0 Then
    Do
     Sleep(100)
    Until _GUICtrlComboBoxEx_GetDroppedState($hCombo) = False
    If $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1] <> $aRestore[$aItemC[1]][1] Then
     ;ConsoleWrite($aItemC[1]&@CRLF&RegRead($sTailReg, $aItemC[1])&@CRLF&$aRestore[$aItemC[1]][1]&@CRLF&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&@CRLF)
     RegWrite($sTailReg, $aItemC[1], "REG_SZ", StringReplace(RegRead($sTailReg, $aItemC[1]), "|"&$aRestore[$aItemC[1]][1]&"|", "|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|")); Update the registry
     _GUICtrlListView_SetItemImage($hList, $aItemC[1], _GUICtrlComboBoxEx_GetCurSel($hCombo)); Update the listview
     $aRestore[$aItemC[1]][1] = $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]; Update the array
     $sHexColor = Hex($aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1], 6)
     $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
     $aRestore[$aItemC[1]][2] = $sHexColor
    EndIf
   EndIf
  EndIf
  $hMsg = GUIGetMsg()
  Select
   Case $hMsg = $GUI_EVENT_CLOSE Or $hMsg = $hOk
    ExitLoop
   Case $hMsg = $hCase
    ; If the case box has been changed, edit the registry, too
    $aItemB = _GUICtrlListView_GetSelectedIndices($hList, True)
    If IsArray($aItemB) Then
     If $aItemB[0] > 0 Then
      If $aRestore[$aItemB[1]][3] = 1 And GUICtrlRead($hCase) = $GUI_UNCHECKED Then
       $sTmp = StringTrimRight(RegRead($sTailReg, $aItemB[1]), 1)
       $sTmp &= 0
       RegWrite($sTailReg, $aItemB[1], "REG_SZ", $sTmp)
       $aRestore[$aItemB[1]][3] = 0
      EndIf
      If $aRestore[$aItemB[1]][3] = 0 And GUICtrlRead($hCase) = $GUI_CHECKED Then
       $sTmp = StringTrimRight(RegRead($sTailReg, $aItemB[1]), 1)
       $sTmp &= 1
       RegWrite($sTailReg, $aItemB[1], "REG_SZ", $sTmp)
       $aRestore[$aItemB[1]][3] = 1
      EndIf
     EndIf
    EndIf
   Case $hMsg = $hDel
    $aSel = _GUICtrlListView_GetSelectedIndices($hList, True)
    If $aSel[0] > 0 Then
     _ArrayDelete($aRestore, $aSel[1])
     $xCount -= 1
     If $xCount > 0 Then
      ReDim $aRestore[$xCount][4]
     Else
      Dim $aRestore[1][4]
     EndIf
     $sText = _GUICtrlListView_GetItemText($hList, $aSel[1])
     $iCount = 0
     RegDelete($sTailReg)
     For $i = 0 To $xCount-1
      If RegRead($sTailReg, $i) <> "" Then RegDelete($sTailReg, $i)
      RegWrite($sTailReg, $i, "REG_SZ", $aRestore[$i][0]&"|"&$aRestore[$i][1]&"|"&$aRestore[$i][3])
     Next
     _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($hList))
    EndIf
   Case $hMsg = $hAdd
    $dupeFlag = False
    If GUICtrlRead($hString) <> "" Then
     For $y = 0 To _GUICtrlListView_GetItemCount($hList)-1
      If StringInStr(_GUICtrlListView_GetItemText($hList, $y), GUICtrlRead($hString)) <> 0 Then
       $dupeFlag = True
       ExitLoop
      EndIf
     Next
     If $dupeFlag Then
      MsgBox(64, "Duplicate", "This search criteria already exists.")
     Else
      $iIndex = _GUICtrlListView_AddItem($hList, GUICtrlRead($hString), _GUICtrlComboBoxEx_GetCurSel($hCombo))
      If GUICtrlRead($hCase) = $GUI_CHECKED Then $sCase = 1
      If GUICtrlRead($hCase) = $GUI_UNCHECKED Then $sCase = 0
      RegWrite($sTailReg, $iIndex, "REG_SZ", GUICtrlRead($hString)&"|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|"&$sCase)
      $sHexColor = Hex($aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1], 6)
      $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
      $xCount += 1
      ReDim $aRestore[$xCount][4]
      $aRestore[$xCount-1][0] = GUICtrlRead($hString)
      $aRestore[$xCount-1][1] = $aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]
      $aRestore[$xCount-1][2] = $sHexColor
      $aRestore[$xCount-1][3] = $sCase
      ;_ArrayDisplay($aRestore, $xCount)
     EndIf
    Else
     MsgBox(64, "Error", "No string was entered. Please enter a string to highlight.")
    EndIf
   Case $hMsg = $hCustom
    $sColorRef = _ChooseColor(0, 255, 0, $Form1)
    If $sColorRef <> -1 Then
     $aColors[4][1] = $sColorRef
     $sHexColor = Hex($sColorRef, 6)
     $sHexColor = '0x' & StringMid($sHexColor, 5, 2) & StringMid($sHexColor, 3, 2) & StringMid($sHexColor, 1, 2)
     ;MsgBox(0, "", $sColorRef&@CRLF&$sHexColor)
     _GUIImageList_Add($hImage3, _GUICtrlComboBoxEx_CreateSolidBitMap($hCombo, $sHexColor, 16, 16))
     _GUIImageList_Swap($hImage3, _GUIImageList_GetImageCount($hImage3)-1, 4)
     _GUIImageList_Remove($hImage3, _GUIImageList_GetImageCount($hImage3)-1)
     _GUICtrlComboBoxEx_SetImageList($hCombo, $hImage3)
     _GUICtrlComboBoxEx_SetCurSel($hCombo, 4); Set the combo box to display 'Custom' with the new color chosen
     ;_GUICtrlListView_SetImageList($hList, $hImage3, 1)
     _GUICtrlComboBoxEx_SetItemImage($hCombo, 4, 4)
     RegWrite($sTailReg, "", "REG_SZ", $sHexColor)
     $aItemC = _GUICtrlListView_GetSelectedIndices($hList, True)
     If $aItemC[0] > 0 Then
      _GUICtrlListView_ClickItem($hList, $aItemC[1])
      _GUICtrlListView_SetItemImage($hList, $aItemC[1], _GUICtrlComboBoxEx_GetCurSel($hCombo))
      RegWrite($sTailReg, $aItemC[1], "REG_SZ", StringReplace(RegRead($sTailReg, $aItemC[1]), "|"&$aRestore[$aItemC[1]][1]&"|", "|"&$aColors[_GUICtrlComboBoxEx_GetCurSel($hCombo)][1]&"|")); Update the registry
      $aRestore[$aItemC[1]][2] = $sHexColor
     EndIf
    EndIf
  EndSelect
WEnd
GUIDelete($Form2)
EndFunc
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $tNMHDR, $IdFrom, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$IdFrom = DllStructGetData($tNMHDR, "IdFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $iCode
  Case $NM_CLICK
   $iSelectFlag = True
  Case $EN_MSGFILTER
   $tMsgFilter = DllStructCreate($tagEN_MSGFILTER, $lParam)
   $aPos = _GUIScrollBars_GetScrollPos($hEdit1, $SB_VERT)
   $PageSize = _GUIScrollBars_GetScrollInfoPage($hEdit1, $SB_VERT)
   Switch DllStructGetData($tMsgFilter, "msg")
    Case 276
     ;ConsoleWrite("Debug: Horz Scroll: x = " & $aPos[0] & "; y = " & $aPos[1] & @LF)
    Case 277
     ;ConsoleWrite("Debug: Vert Scroll: y = " & $aPos & @LF)
     If $aPos < $nMax - $PageSize Then
      GUICtrlSetState($hFollow, $GUI_UNCHECKED)
      $scrollFlag = False
     Else
      GUICtrlSetState($hFollow, $GUI_CHECKED)
      $scrollFlag = True
     EndIf
     ;ConsoleWrite($aPos&" "&$nMax&"("&$nMax - $PageSize&")"&@LF)
   EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
If $hWnd = $Form1 Then
        $iGUIWidth = BitAND($ilParam, 0xFFFF)
        $iGUIHeight = BitShift($ilParam, 16)
  Local $iWidth = _WinAPI_LoWord($ilParam)
  Local $iHeight = _WinAPI_HiWord($ilParam)
  _WinAPI_MoveWindow($hEdit1, 1, 21, $iWidth - 2, $iHeight - 21)
  If $iGUIWidth = @DesktopWidth Then
   $iRE_Ht = $iGUIHeight - ($iGUIHeight - 21)
   GUICtrlSetPos($hOpen, 0, 0, 70, 20)
   GUICtrlSetPos($hHilite, 72, 0, 70, 20)
   GUICtrlSetPos($hFollow, 148, 1, 70, 20)
   GUICtrlSetPos($hInput, 224, 3, $iGUIWidth-224, 19)
   $nMax = _GUIScrollBars_GetScrollInfoMax($hEdit1, $SB_VERT)
   ; If at the end of the log and maximized, push the last line to the bottom of the edit...
   ; Otherwise, a blank gap appears at the bottom
   If GUICtrlRead($hFollow) = $GUI_CHECKED Then _GUICtrlRichEdit_ScrollLineOrPage($hEdit1, "ld")
  Else
   GUICtrlSetPos($hOpen, 0, 0, 70, 20)
   GUICtrlSetPos($hHilite, 71, 0, 70, 20)
   GUICtrlSetPos($hFollow, 147, 1, 70, 20)
   GUICtrlSetPos($hInput, 224, 1, 475, 19)
   $nMax = _GUIScrollBars_GetScrollInfoMax($hEdit1, $SB_VERT)
  EndIf
EndIf
EndFunc
Func _Exit()
_GUICtrlRichEdit_Destroy($hEdit1)
EndFunc
Link to comment
Share on other sites

Ok, it turns out that the script isn't choking, it's just taking a very long time. Here's the loop that's slowing things down. Can someone please help me make this loop work a bit faster? Thanks!

If $var2 <> $var1 Then
   ConsoleWrite("Read in " & $var2 - $var1 & " bytes" &  @CRLF)
   ConsoleWrite("New data" & @CRLF)
   _GUICtrlStatusBar_SetText($tStatus, "Read in " & $var2 - $var1 & " bytes", 0)
   $file = _FileOpenAPI($sFile)
   $read = _FileReadAPI($file, $var2 - $var1, $var1)
   _FileCloseAPI($file)
   ConsoleWrite($read & @CRLF)
   $iOldLines = _GUICtrlRichEdit_GetLineCount($hEdit1)
   _GUICtrlRichEdit_PauseRedraw($hEdit1)
   $iLineVisible = _GUICtrlRichEdit_GetNumberOfFirstVisibleLine($hEdit1)
   _GUICtrlRichEdit_SetText($hEdit1, FileRead($sFile))
   $iNewLines = _GUICtrlRichEdit_GetLineCount($hEdit1)
   If $var1 <> 0 Then
    For $s = 0 To UBound($aRestore) - 1
     If $aRestore[$s][3] = 1 Then $fCase = True
     If $aRestore[$s][3] = 0 Then $fCase = False
     For $q = $iOldLines To $iNewLines
      If StringInStr(_GUICtrlRichEdit_GetTextInLine($hEdit1, $q), $aRestore[$s][0], $fCase) <> 0 Then
       ReDim $aLines[$iLineCount][2]
       $aLines[$iLineCount-1][0] = $q
       $aLines[$iLineCount-1][1] = $aRestore[$s][1]
       $iLineCount += 1
      EndIf
     Next
    Next
   EndIf
   For $l = 0 To UBound($aLines)-1
    If $aLines[$l][0] <> "" Then
     $iFirst = _GUICtrlRichEdit_GetFirstCharPosOnLine($hEdit1, $aLines[$l][0])
     $iLen = _GUICtrlRichEdit_GetLineLength($hEdit1, $aLines[$l][0])
     _GUICtrlRichEdit_SetSel($hEdit1, $iFirst, $iFirst+$iLen, True)
     _GUICtrlRichEdit_SetCharBkColor($hEdit1, $aLines[$l][1])
    EndIf
   Next
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...