Function Reference


_GUICtrlRichEdit_ReplaceText

Replaces selected text

#include <GuiRichEdit.au3>
_GUICtrlRichEdit_ReplaceText ( $hWnd, $sText [, $bCanUndo = True] )

Parameters

$hWnd Handle to the control
$sText Replacement text
$bCanUndo [optional] Can operation can be undone? True (Default) or False

Return Value

Success: True.
Failure: False and sets the @error flag to non-zero.
@error: 101 - $hWnd is not a handle
103 - $bCanUndo must be True or False
-1 - no text is selected

Related

_GUICtrlRichEdit_AppendText, _GUICtrlRichEdit_InsertText, _GUICtrlRichEdit_SetText

See Also

Search EM_REPLACESEL in MSDN Library.

Example

#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
        Local $hGui = GUICreate("RichEdit Replace Text (v" & @AutoItVersion & ")", 340, 350, -1, -1)
        Local $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 320, 220, _
                        BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
        Local $idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
        Local $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30)
        GUISetState(@SW_SHOW)

        _GUICtrlRichEdit_SetText($hRichEdit, "First paragraph")
        Local $iMsg, $iStep = 0
        While True
                $iMsg = GUIGetMsg()
                Select
                        Case $iMsg = $GUI_EVENT_CLOSE
                                _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes
                                ; GUIDelete()   ; is OK too
                                Exit
                        Case $iMsg = $idBtnNext
                                $iStep += 1
                                Switch $iStep
                                        Case 1
                                                _GUICtrlRichEdit_SetSel($hRichEdit, 0, 5)
                                        Case 2
                                                _GUICtrlRichEdit_ReplaceText($hRichEdit, "1st")
                                                GUICtrlSetData($idLblMsg, "Text has been replaced")
                                        Case 3
                                                _GUICtrlRichEdit_SetSel($hRichEdit, 0, 3)
                                                _GUICtrlRichEdit_ReplaceText($hRichEdit, "")
                                                GUICtrlSetData($idLblMsg, "1st has been deleted")
                                                GUICtrlSetState($idBtnNext, $GUI_DISABLE)
                                EndSwitch
                EndSelect
        WEnd
EndFunc   ;==>Example