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

Main()

Func Main()
	Local $hGui, $btnNext, $iStep = 0, $lblMsg, $hRichEdit, $s
	$hGui = GUICreate(StringTrimRight(@ScriptName, 4), 420, 350, -1, -1)
	$hRichEdit = _GUICtrlRichEdit_Create($hGui, 'Это тест.', 10, 10, 400, 220, _
			BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
	$lblMsg = GUICtrlCreateLabel("", 10, 235, 400, 75)
	$btnNext = GUICtrlCreateButton("Далее", 270, 310, 60, 30)
	GUISetState()

	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE
				_GUICtrlRichEdit_Destroy($hRichEdit)
				GUIDelete()
				Exit
			Case $btnNext
				$iStep += 1
				Switch $iStep
					Case 1
						_GUICtrlRichEdit_SetSel($hRichEdit, 0, -1)
						$s = _GUICtrlRichEdit_StreamToVar($hRichEdit)
						GUICtrlSetData($lblMsg, "Чтение кода RTF в переменную:" & @CR & $s)
						; ClipPut($s)
					Case 2
						_GUICtrlRichEdit_SetText($hRichEdit, "")
						$s = StringReplace($s, 'fcharset204 MS Shell Dlg;', 'fcharset204 Times New Roman;') ; Изменение шрифта с помощью тегов
						$s = StringRegExpReplace($s, '\\fs\d{1,2}', '\\fs32') ; Изменение размера шрифта с помощью тегов
						_GUICtrlRichEdit_StreamFromVar($hRichEdit, $s)
						GUICtrlSetData($lblMsg, "Вставка кода RTF из переменной")
					Case 3
						_GUICtrlRichEdit_SetSel($hRichEdit, 2, 6)
						_GUICtrlRichEdit_StreamFromVar($hRichEdit, $s)
						GUICtrlSetData($lblMsg, "Замена выделенного: умышленная путаница!")
						GUICtrlSetState($btnNext, $GUI_DISABLE)
				EndSwitch
		EndSwitch
	WEnd
EndFunc   ;==>Main