Jump to content

Search the Community

Showing results for tags 'RichEdit Rich Text Tool'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Location


WWW


Interests

Found 1 result

  1. After a week’s work with RichEdit controls, I’ve made some observations and come to some conclusions that may help others. The main two are: Rich Text is relatively easy when used inside an AutoIt GUI ... as there are ample commands in the _GUICtrlRichText_*** UDF set. Rich Text is fairly difficult when you start to work with multiple fields and with RTF from other sources, largely because of the wide variations in implementations ... but sometimes due to AutoIt-specific support for rich text formats. As a result of my investigation—and with assistance from mLipok—I’ve produced a Rich Text Tool to help me follow the details of the embedded format definitions. I’m offering it here to help others fathom these details. In the paragraphs that follow the code, I list some of my observations/conclusions in hopes that others might shed additional light. ;======================================== ; Tool for analyzing AutoIt's Rich Text Processing Features ; (and to demonstrate serveral of the common methods) ; >> based on the example script developed by mLipok ; >> with these "tool" enhancements by qwert ; June, 2014 ;======================================== #include <GUIConstantsEx.au3> #include <GuiRichEdit.au3> #include <WindowsConstants.au3> Local $hGui, $hRichEdit, $hRichEdit2, $hRichEdit3, $hRichEdit123 Local $iMsg $hGui = GUICreate("Rich Edit Tools", 1260, 400, -1, 200) ;#Region Create all RichEdit controls $hRichEdit1 = _GUICtrlRichEdit_Create($hGui, "This is a first test.", 10, 10, 300, 100, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit1, @CRLF & "This is more text" & @CRLF) _GUICtrlRichEdit_SetSel($hRichEdit1, 0, 22) _GUICtrlRichEdit_SetFont($hRichEdit1, 14, "Arial") _GUICtrlRichEdit_SetSel($hRichEdit1, -1, -1) $hRichEdit2 = _GUICtrlRichEdit_Create($hGui, "This is a second test.", 10, 130, 300, 100, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit2, @CRLF & "This is more text" & @CRLF) _GUICtrlRichEdit_SetSel($hRichEdit2, 10, 22) _GUICtrlRichEdit_SetFont($hRichEdit2, 14, "Arial") _GUICtrlRichEdit_SetSel($hRichEdit2, -1, -1) $hRichEdit3 = _GUICtrlRichEdit_Create($hGui, "This is a third test.", 10, 250, 300, 100, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit3, @CRLF & "This is more text" & @CRLF) _GUICtrlRichEdit_SetSel($hRichEdit3, 10, 21) _GUICtrlRichEdit_SetFont($hRichEdit3, 14, "Arial") _GUICtrlRichEdit_SetSel($hRichEdit3, -1, -1) $hRichEdit123 = _GUICtrlRichEdit_Create($hGui, "This is the combined result.", 320, 30, 300, 280, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_AppendText($hRichEdit123, @CRLF & @CRLF) ;#EndRegion Create all RichEdit controls $hVerbatim = GUICtrlCreateEdit ("This is the resulting Rich Text.", 630, 30, 300, 280, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $hRichResult = _GUICtrlRichEdit_Create($hGui, "Reserved for process result.", 940, 30, 300, 280, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) GUISetFont(16, 700, 0, "Arial") GUICtrlCreateLabel("Combined", 324, 6, 120, 24) GUICtrlCreateLabel("Verbatim", 634, 6, 120, 24) GUICtrlCreateLabel("Result", 944, 6, 120, 24) GUICtrlCreateLabel("\", 562, 310, 120, 24) GUICtrlCreateLabel("\", 872, 310, 120, 24) GUICtrlCreateLabel("/", 680, 310, 120, 24) GUICtrlCreateLabel("/", 990, 310, 120, 24) GUISetFont(12, 400, 0, "Arial") GUICtrlCreateLabel("These tools use the copy/paste method of combining the rich text fields.", 320, 372, 500, 24) $Combine = GUICtrlCreateButton("Combine", 104, 364, 120, 24) GUICtrlSetTip(-1, "Click to redo the combining operation") $ProcessRich = GUICtrlCreateButton("Process", 564, 330, 120, 24) GUICtrlSetTip(-1, "Click to produce Verbatim from Combined") $ProcessVerb = GUICtrlCreateButton("Process", 874, 330, 120, 24) GUICtrlSetTip(-1, "Click to produce Result from Verbatim") GUISetState(@SW_SHOW) Sleep(800) ; for effect only _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit1, $hRichEdit123) ; Copying $hRichEdit1 to $hRichEdit123 Sleep(800) _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit2, $hRichEdit123) ; Copying $hRichEdit2 to $hRichEdit123 Sleep(800) _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit3, $hRichEdit123) ; Copying $hRichEdit3 to $hRichEdit123 Local $Var = _GUICtrlRichEdit_StreamToVar($hRichEdit123, True) $Var = StringReplace($Var, "MS Shell Dlg", "Arial", 0) ; <<<< example of a DIRECT EDIT to change the default font Sleep(800) ;MsgBox(0, "Result", $Var, 0) ; OPTION to view before storing _GUICtrlRichEdit_StreamFromVar ($hRichEdit123, $Var) _GUICtrlRichEdit_StreamToFile($hRichEdit123, @ScriptDir & "\Rich123.rtf", True) GUICtrlSetData($hVerbatim, $Var) Sleep(800) ; again, for effect MsgBox(0, "", "Done", 1) While True $iMsg = GUIGetMsg() Select Case $iMsg = $Combine _GUICtrlRichEdit_SetSel($hRichEdit123, 0, -1) _GUICtrlRichEdit_ReplaceText($hRichEdit123, "New result:" & @CRLF & @CRLF) Sleep(800) ; for effect only _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit1, $hRichEdit123) Sleep(800) ; for effect only _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit2, $hRichEdit123) Sleep(800) ; for effect only _GUICtrlRichEdit_CopyAllToRichEdit($hRichEdit3, $hRichEdit123) Sleep(800) ; again, for effect MsgBox(0, "", "Done" & @CRLF & "Verbatim is unchanged at this point." & @CRLF & "Click Process to update it.", 2) Case $iMsg = $ProcessRich Local $Var = _GUICtrlRichEdit_StreamToVar($hRichEdit123, True) GUICtrlSetData($hVerbatim, $Var) MsgBox(0, "", "Done", 1) Case $iMsg = $ProcessVerb _GUICtrlRichEdit_StreamFromVar ($hRichResult, GUICtrlRead($hVerbatim)) MsgBox(0, "", "Done", 1) Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit1) ; needed unless script crashes _GUICtrlRichEdit_Destroy($hRichEdit2) ; needed unless script crashes _GUICtrlRichEdit_Destroy($hRichEdit3) ; needed unless script crashes _GUICtrlRichEdit_Destroy($hRichResult) ; needed unless script crashes _GUICtrlRichEdit_Destroy($hRichEdit123) ; needed unless script crashes ; GUIDelete() ; is OK too Exit EndSelect WEnd Func _GUICtrlRichEdit_CopyAllToRichEdit(ByRef $hSourceRichEdit, ByRef $hDestinationRichEdit) Local $aSelection = _GUICtrlRichEdit_GetSel($hSourceRichEdit) ; check for current selection in source control _GUICtrlRichEdit_SetSel($hSourceRichEdit, 0, -1) ; select all contents in source control _GUICtrlRichEdit_Copy($hSourceRichEdit) ; copy selected contents from source control _GUICtrlRichEdit_Paste($hDestinationRichEdit) ; paste content to destination control _GUICtrlRichEdit_SetSel($hSourceRichEdit, $aSelection[0], $aSelection[1]) ; revert back selection in source control EndFunc ;==>_GUICtrlRichEdit_CopyAllToRichEdit Observations of AutoIt’s features and limitations: There is no effective way to assign a default font/size for a RichEdit control. You must assign the font/size to existing segments of characters ... or to the entire contents of a control (with Select All). There is no "native method" to directly write more that one control to a file*. StreamToFile handles formatting well, but can only stream out one named control to a named file. There is no option to append to these files (as there is with normal writes). (* as demonstrated by this tool, methods exist to combine RichEdit controls into a single control for use with the StreamToFile operation.) Likewise, copy to clipboard (_GuiCtrlRichEdit_Copy) preserves RichText formatting and can be useful in moving field content. From what I understand, the clipboard maintains both the RTF and text-only versions of the content. Paste and Paste Special determine which version an application receives. AutoIt's normal file and line writes are for text/data only and cannot be used for RichText controls. _GuiCtrlRichEdit_GetText gets only the text content, without character formatting. If you want to work directly with the RTF syntax, you must first to stream the RichEdit to a Variable ... and then use normal search/replace/add string operations to alter the contents of the variable. You must then update the original RichEdit using StreamFromVar in order to display your result or write to a file (StreamToFile). In Summary Think of a RichEdit control as a “processed container” for format-encoded text. The content is displayed according to rules that are embedded with the text. You can’t see the rules. You only observe their effects. And you can only use the RichEdit UDF actions to make changes to the content in a RichEdit control. If you want to see and work with those rules “verbatim”, first stream the RichEdit contents into a variable and then place the contents of that variable into a normal edit control. Once there, you can parse the rich text statements and apply literal edits and exchanges using String operations. Stream the contents of the edit control back into a RichEdit control to see the effects of those changes. The Rich Edit Tools script provides examples of the types of conversions that can be made. The field on the far right is the “interpreted result” of the verbatim text. Note the direct edit of the default font in the script. (A question: note the use of ByRef in the Function. Since it works without them, what is their purpose in this instance?) Everything I’ve outlined here is subject to correction by anyone with more in-depth experience and understanding. Please feel free to contribute. Thanks to mLipok for posting the basis for this example script, in particular, the _GUICtrlRichEdit_CopyAllToRichEdit method for combining field content.
×
×
  • Create New...