mike1950r Posted July 21 Share Posted July 21 Hi, is there a way to enable undo for _GUICtrlRichEdit_SetText ? Thanks for a tip. Cheers mike Link to comment Share on other sites More sharing options...
ahmet Posted July 21 Share Posted July 21 Hi, Based on this here is modified example from help file: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Example() Func Example() Local $hGui, $iMsg, $idBtnNext, $iStep = 0, $idLblMsg, $hRichEdit $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1) $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60) $idBtnNext = GUICtrlCreateButton("Next", 270, 310, 40, 30) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetText($hRichEdit, "First paragraph") 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_SetUndoLimit($hRichEdit, 200) GUICtrlSetData($idLblMsg, "Increased the number of actions that can stored in the undo queue from 100 to 200") Case 2 _GUICtrlRichEdit_SetUndoLimit($hRichEdit, 0) GUICtrlSetData($idLblMsg, "Undo is disabled") GUICtrlSetState($idBtnNext, $GUI_DISABLE) EndSwitch EndSelect WEnd EndFunc ;==>Example There is also message EM_SETTEXTEX. Link to comment Share on other sites More sharing options...
Nine Posted July 21 Share Posted July 21 expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Global $g_idLblMsg Example() Func Example() Local $hGui = GUICreate("RichEdit Get/Set 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)) $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetSel($hRichEdit, 0, -1, True) _GUICtrlRichEdit_ReplaceText($hRichEdit, "This is Set text.", True) Report("Text: " & @CRLF & @CRLF & _GUICtrlRichEdit_GetText($hRichEdit)) _GUICtrlRichEdit_Undo($hRichEdit) Local $iMsg While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes ; GUIDelete() ; is OK too Exit EndSelect WEnd EndFunc ;==>Example Func Report($sMsg) GUICtrlSetData($g_idLblMsg, $sMsg) EndFunc ;==>Report “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
mike1950r Posted July 21 Author Share Posted July 21 thanks lot for the posts. the replace-option instead of set-option I know. This is why I asked if undo can be enabled for the set-option. BTW the undo limit is already set to a higher value, but even for set-option it would be enough if it was just 1. So unfortunately I still do not know, how I could get the undo-option activated for _GUICtrlRichEdit_SetText. cheers mike Link to comment Share on other sites More sharing options...
Andreik Posted July 21 Share Posted July 21 (edited) Changed a little bit @Nine's example: expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Global $g_idLblMsg Example() Func Example() Local $hGui = GUICreate("RichEdit Get/Set 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)) $g_idLblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetSel($hRichEdit, 0, -1, True) _GUICtrlRichEdit_SetText2($hRichEdit, "This is Set text.", True) Report("Text: " & @CRLF & @CRLF & _GUICtrlRichEdit_GetText($hRichEdit)) _GUICtrlRichEdit_Undo($hRichEdit) Local $iMsg While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) ; needed unless script crashes ; GUIDelete() ; is OK too Exit EndSelect WEnd EndFunc ;==>Example Func Report($sMsg) GUICtrlSetData($g_idLblMsg, $sMsg) EndFunc ;==>Report Func _GUICtrlRichEdit_SetText2($hWnd, $sText, $bCanUndo = False) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) Local $tSetText = DllStructCreate($tagSETTEXTEX) DllStructSetData($tSetText, 1, ($bCanUndo ? $ST_KEEPUNDO : $ST_DEFAULT)) DllStructSetData($tSetText, 2, $CP_ACP) Local $iRet If StringLeft($sText, 5) <> "{\rtf" And StringLeft($sText, 5) <> "{urtf" Then DllStructSetData($tSetText, 2, $CP_UNICODE) $iRet = _SendMessage($hWnd, $EM_SETTEXTEX, $tSetText, $sText, 0, "struct*", "wstr") Else $iRet = _SendMessage($hWnd, $EM_SETTEXTEX, $tSetText, $sText, 0, "struct*", "STR") EndIf If Not $iRet Then Return SetError(700, 0, False) Return True EndFunc Basically the flags member in SETTEXTEX structure is hardcoded with ST_DEFAULT whici means that the undo stack is deleted. Changing ST_DEFAULT with ST_KEEPUNDO the undo stack is preserved. I think there should be a third parameter added to _GUICtrlRichEdit_SetText(), at least for symmetry. Anyway, the help file is wrong stating that the undo stack is preserved, when it's clearly not. Until anything it's changed you can use _GUICtrlRichEdit_SetText2() like in the example above. Edited July 21 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
mike1950r Posted July 22 Author Share Posted July 22 Thanks Andreik, I have tested your modified _GUICtrlRichEdit_SetText2. This works fine and enables UNDO. (if selection is done before) If no selection is done, it works, but no UNDO. Is there a way to get the UNDO working without selection in window-edit? We need the selection for other purposes. Cheers mike Link to comment Share on other sites More sharing options...
Solution Andreik Posted July 22 Solution Share Posted July 22 I'm not sure what are you talking about. Selection has nothing to do with undo, as you can see below: #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Local $hGui = GUICreate("RichEdit Get/Set Text (v" & @AutoItVersion & ")", 340, 350) Local $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 320, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetState(@SW_SHOW) Sleep(5000) _GUICtrlRichEdit_SetText2($hRichEdit, "This is Set text.", True) Sleep(5000) _GUICtrlRichEdit_Undo($hRichEdit) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Func _GUICtrlRichEdit_SetText2($hWnd, $sText, $bCanUndo = False) If Not _WinAPI_IsClassName($hWnd, $__g_sRTFClassName) Then Return SetError(101, 0, False) Local $tSetText = DllStructCreate($tagSETTEXTEX) DllStructSetData($tSetText, 1, ($bCanUndo ? $ST_KEEPUNDO : $ST_DEFAULT)) DllStructSetData($tSetText, 2, $CP_ACP) Local $iRet If StringLeft($sText, 5) <> "{\rtf" And StringLeft($sText, 5) <> "{urtf" Then DllStructSetData($tSetText, 2, $CP_UNICODE) $iRet = _SendMessage($hWnd, $EM_SETTEXTEX, $tSetText, $sText, 0, "struct*", "wstr") Else $iRet = _SendMessage($hWnd, $EM_SETTEXTEX, $tSetText, $sText, 0, "struct*", "STR") EndIf If Not $iRet Then Return SetError(700, 0, False) Return True EndFunc mike1950r 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
mike1950r Posted July 22 Author Share Posted July 22 Hi Andreik, it was my fault. Your script is OK. I had made a mistake in updating my Menu-Entry for the Undo. It asks _GUICtrlRichEdit_CanUndo to enable or disable this menu-entry. Your Undo was working, but my menu-entry UNDO was not enabled. Exellent. I can use now _GUICtrlRichEdit_SetText with included Undo. Thanks lot. Cheers mike Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now