Function Reference


_GUICtrlEdit_ReplaceSel

Replaces the current selection

#include <GuiEdit.au3>
_GUICtrlEdit_ReplaceSel ( $hWnd, $sText [, $bUndo = True] )

Parameters

$hWnd Control ID/Handle to the control
$sText String containing the replacement text.
$bUndo [optional] Specifies whether the replacement operation can be undone:
    True - The operation can be undone.
    False - The operation cannot be undone.

Return Value

None.

Remarks

Use the _GUICtrlEdit_ReplaceSel() to replace only a portion of the text in an edit control.
If there is no current selection, the replacement text is inserted at the current location of the caret.

Related

_GUICtrlEdit_GetSel, _GUICtrlEdit_SetSel

Example

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#include <GuiStatusBar.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
        Local $hStatusBar, $idEdit, $hGUI
        Local $sWow64 = ""
        If @AutoItX64 Then $sWow64 = "\Wow6432Node"
        Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir") & "\include\_ReadMe_.txt"
        Local $aPartRightSide[3] = [200, 378, -1]

        ; Create GUI
        $hGUI = GUICreate("Edit Replace Sel", 400, 300)
        $idEdit = GUICtrlCreateEdit("", 2, 2, 394, 268, BitOR($ES_WANTRETURN, $WS_VSCROLL))
        $hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aPartRightSide)
        _GUICtrlStatusBar_SetIcon($hStatusBar, 2, 97, "shell32.dll")
        GUISetState(@SW_SHOW)

        ; Set Margins
        _GUICtrlEdit_SetMargins($idEdit, BitOR($EC_LEFTMARGIN, $EC_RIGHTMARGIN), 10, 10)

        ; Set Text
        _GUICtrlEdit_SetText($idEdit, FileRead($sFile))

        ; Set Sel
        _GUICtrlEdit_SetSel($idEdit, 0, 8)

        MsgBox($MB_SYSTEMMODAL, "Information", "Replace Sel")
        _GUICtrlEdit_ReplaceSel($idEdit, StringFormat("%d/%2d/%4d", @MON, @MDAY, @YEAR))

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
        GUIDelete()
EndFunc   ;==>Example