#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIRichEdit.au3>
Global $iLast_Pos = 0
Global $sLast_Search = ""
$hGUI = GUICreate("Example (" & StringTrimRight(@ScriptName, 4) & ")", 320, 350, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, "This is a test, no errors here.", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
$nSearch_Bttn = GUICtrlCreateButton("Search", 140, 310, 70, 30)
$nSearchNext_Bttn = GUICtrlCreateButton("Search Next", 220, 310, 90, 30)
GUISetState()
While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
GUIDelete()
Exit
Case $nSearch_Bttn
$sLast_Search = InputBox("Search in RichEdit", "Enter search request:", $sLast_Search, "", -1, -1, Default, Default, 0, $hGUI)
If Not @error Then ContinueCase
Case $nSearchNext_Bttn
If $sLast_Search = "" Then ContinueLoop
_GUICtrlRichEdit_SetSel($hRichEdit, $iLast_Pos, $iLast_Pos)
$iAnchor = _GUICtrlRichEdit_FindText($hRichEdit, $sLast_Search)
$iActive = $iAnchor + StringLen($sLast_Search)
_GUICtrlRichEdit_SetSel($hRichEdit, $iAnchor, $iActive)
$iLast_Pos = $iActive
If $iLast_Pos = 0 Or $iAnchor = -1 Then
$iAsk = MsgBox(52, 'Attention', 'End of text, serach from the begining?', 0, $hGUI)
If $iAsk = 6 Then
ControlClick($hGUI, "", $nSearchNext_Bttn)
EndIf
EndIf
EndSwitch
WEnd