TheAutomator Posted yesterday at 11:01 AM Posted yesterday at 11:01 AM (edited) doing _GUICtrlRichEdit_StreamToFile($rich_edit, 'test.rtf') and _GUICtrlRichEdit_StreamFromFile($rich_edit, 'test.rtf') on repeat keeps adding a newline at the end of the text over and over every step, how can i prevent this? Edited yesterday at 11:37 AM by TheAutomator Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone
Solution Nine Posted yesterday at 01:57 PM Solution Posted yesterday at 01:57 PM Seems that Windows automatically add a new paragraph at the end of the document. But it can be easily removed before writing the rich edit to the file. You could create a new ticket in Bug Tracker and ask the devs to modify _GUICtrlRichEdit_StreamToFile in order to delete the new added paragraph at the end. In the mean time, you will need to replace the UDF callback with your own. Here how you could do it : expandcollapse popup#include <GUIConstants.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", True) $__g_pGRC_StreamToFileCallback = DllCallbackRegister("__GCR_StreamToFileCallbackEx", "dword", "long_ptr;ptr;long;ptr") Example() Func Example() Local $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1) Local $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) Local $idBtnIn = GUICtrlCreateButton("In", 270, 310, 40, 30) Local $idBtnOut = GUICtrlCreateButton("Out", 170, 310, 40, 30) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetText($hRichEdit, "First paragraph") While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtnOut _GUICtrlRichEdit_StreamToFile($hRichEdit, @DesktopDir & "\gcre.rtf") Case $idBtnIn _GUICtrlRichEdit_StreamFromFile($hRichEdit, @DesktopDir & "\gcre.rtf") EndSwitch WEnd _GUICtrlRichEdit_Destroy($hRichEdit) EndFunc ;==>Example Func __GCR_StreamToFileCallbackEx($hFile, $pBuf, $iBuflen, $pQbytes) Local $tQbytes = DllStructCreate("long", $pQbytes) DllStructSetData($tQbytes, 1, 0) Local $tBuf = DllStructCreate("char[" & $iBuflen & "]", $pBuf) Local $s = StringReplace(DllStructGetData($tBuf, 1), "\par" & @CRLF & "}", @CRLF & "}") FileWrite($hFile, $s) DllStructSetData($tQbytes, 1, StringLen($s)) Return 0 EndFunc ;==>__GCR_StreamToFileCallbackEx ps. Not much testing in there and I did not test all the options, I'll let you do that if you will... “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) Debug Messages Monitor UDF Screen Scraping Multi-Threading Made Easy
TheAutomator Posted yesterday at 02:08 PM Author Posted yesterday at 02:08 PM 10 minutes ago, Nine said: Seems that Windows automatically add a new paragraph at the end of the document. But it can be easily removed before writing the rich edit to the file. You could create a new ticket in Bug Tracker and ask the devs to modify _GUICtrlRichEdit_StreamToFile in order to delete the new added paragraph at the end. In the mean time, you will need to replace the UDF callback with your own. Here how you could do it : expandcollapse popup#include <GUIConstants.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", True) $__g_pGRC_StreamToFileCallback = DllCallbackRegister("__GCR_StreamToFileCallbackEx", "dword", "long_ptr;ptr;long;ptr") Example() Func Example() Local $hGui = GUICreate("Example (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")", 320, 350, -1, -1) Local $hRichEdit = _GUICtrlRichEdit_Create($hGui, "This is a test.", 10, 10, 300, 220, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) Local $idBtnIn = GUICtrlCreateButton("In", 270, 310, 40, 30) Local $idBtnOut = GUICtrlCreateButton("Out", 170, 310, 40, 30) GUISetState(@SW_SHOW) _GUICtrlRichEdit_SetText($hRichEdit, "First paragraph") While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idBtnOut _GUICtrlRichEdit_StreamToFile($hRichEdit, @DesktopDir & "\gcre.rtf") Case $idBtnIn _GUICtrlRichEdit_StreamFromFile($hRichEdit, @DesktopDir & "\gcre.rtf") EndSwitch WEnd _GUICtrlRichEdit_Destroy($hRichEdit) EndFunc ;==>Example Func __GCR_StreamToFileCallbackEx($hFile, $pBuf, $iBuflen, $pQbytes) Local $tQbytes = DllStructCreate("long", $pQbytes) DllStructSetData($tQbytes, 1, 0) Local $tBuf = DllStructCreate("char[" & $iBuflen & "]", $pBuf) Local $s = StringReplace(DllStructGetData($tBuf, 1), "\par" & @CRLF & "}", @CRLF & "}") FileWrite($hFile, $s) DllStructSetData($tQbytes, 1, StringLen($s)) Return 0 EndFunc ;==>__GCR_StreamToFileCallbackEx ps. Not much testing in there and I did not test all the options, I'll let you do that if you will... Thanks for the help, added ticket to bugtracker Retro Console, NestedArrayDisplay UDF foldermaker-pro-clone
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