Jump to content

RichEdit toggle wrap/unwrap - how?


orbs
 Share

Recommended Posts

when the RichEdit is created with style $WS_HSCROLL, the text is not wrapped and there is an horizontal scrollbar.

the opposite is also true: when the RichEdit is created without style $WS_HSCROLL, the text is wrapped, and there is no horizontal scrollbar.

so far so good. now i want to toggle wrap/unwrap. i tried doing it by changing the style of the RichEdit with this:

_WinAPI_SetWindowLong($hRichEdit, $GWL_STYLE, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))

(the style used by _GUICtrlRichEdit_Create is the same, but with $WS_HSCROLL).

this does not work - or perhaps it does work, but i don;t see it, because it makes the entire RichEdit disappear. where am i going wrong?

this is the full demo script:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#NoTrayIcon

#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

; build GUI
Global Const $nGUI_MaxW = 500, $nGUI_MaxH = 100
Global $nGUI_W = 720, $nGUI_H = 500, $nRichEditOffset = 10, $nRichEditOffsetTop = 30
Global $nToolbarHeight = $nRichEditOffsetTop
Global $hGui = GUICreate('RichEdit wrap/unwrap test', $nGUI_W, $nGUI_H, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_SYSMENU))
GUISetBkColor(0xCCDDEE)
; - toolbar ; ** requires an extra lower contour if main rich edit is not docked to edges
Global $gToolbarBackground = GUICtrlCreateLabel('', 0, 0, $nGUI_W, $nToolbarHeight)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT))
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $gToolbarBackgroundContour = GUICtrlCreateLabel('', 0, $nToolbarHeight+1, $nGUI_W, 1)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT))
GUICtrlSetBkColor(-1, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
; -- wrap/unwrap
Global $bWrap = False
Global $gWrap = GUICtrlCreateCheckbox('Wrap', 3, 3, 48, 24, $BS_PUSHLIKE)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))
; - main
Global $hRichEdit = _GUICtrlRichEdit_Create($hGui, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz' & @LF, $nRichEditOffset, $nRichEditOffset + $nRichEditOffsetTop, $nGUI_W - $nRichEditOffset * 2, $nGUI_H - $nRichEditOffset * 2 - $nRichEditOffsetTop - 24, BitOR($ES_MULTILINE, $ES_READONLY, $WS_HSCROLL, $WS_VSCROLL))
_GUICtrlRichEdit_SetSel($hRichEdit, 0, -1, True)
_GUICtrlRichEdit_SetFont($hRichEdit, Default, 'Courier New')
GUISetState()
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO")
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")
; work with GUI
Global $iMsg = 0
While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
        Case $gWrap
            $bWrap = Not $bWrap
            If $bWrap Then
                _WinAPI_SetWindowLong($hRichEdit, $GWL_STYLE, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            Else
                _WinAPI_SetWindowLong($hRichEdit, $GWL_STYLE, BitOR($ES_MULTILINE, $ES_READONLY, $WS_HSCROLL, $WS_VSCROLL))
            EndIf
    EndSwitch
WEnd

#region resizing funcs
Func _WM_GETMINMAXINFO($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    Local $tagMaxinfo
    If $hWnd = $hGui Then
        $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
        DllStructSetData($tagMaxinfo, 7, $nGUI_MaxW) ; min X
        DllStructSetData($tagMaxinfo, 8, $nGUI_MaxH) ; min Y
        Return 0
    EndIf
EndFunc   ;==>_WM_GETMINMAXINFO

Func _WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    ; ref: http://www.autoitscript.com/forum/topic/123904-solved-auto-resizing-richedit-control/#entry860464
    If $hWnd = $hGui Then
        Local $iWidth = _WinAPI_LoWord($lParam) ; the entire GUI internal width
        Local $iHeight = _WinAPI_HiWord($lParam) ; the entire GUI internal height
        _WinAPI_MoveWindow($hRichEdit, $nRichEditOffset, $nRichEditOffset + $nRichEditOffsetTop, $iWidth - $nRichEditOffset * 2, $iHeight - $nRichEditOffset * 2 - $nRichEditOffsetTop)
    EndIf
EndFunc   ;==>_WM_SIZE
#endregion resizing funcs

thanks for any hints.

EDIT: there is the possibility of destroying and re-creating the RichEdit: '?do=embed' frameborder='0' data-embedContent>>

i'll try it unless i can find something less brutal.

Edited by orbs

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

  • 2 weeks later...
  • Moderators

orbs,

Like you, the only way I can get this to work is by destroying and recreating the RichEdit: :wacko:

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

Global $bWrap = False

$sText = "A very very long line that needs to wrap in the RuchEdit and so is useful in the context of this example"
For $i = 1 To 3
    $sText &= @CRLF & $sText
Next

; build GUI
Global Const $nGUI_MaxW = 500, $nGUI_MaxH = 100
Global $nGUI_W = 720, $nGUI_H = 500, $nRichEditOffset = 10, $nRichEditOffsetTop = 30

Global $hGui = GUICreate('RichEdit wrap/unwrap test', $nGUI_W, $nGUI_H)
GUISetBkColor(0xCCDDEE)

; -- wrap/unwrap
Global $cWrap = GUICtrlCreateCheckbox('Wrap', 3, 3, 48, 24, $BS_PUSHLIKE)

; - main
Global $hRichEdit = _GUICtrlRichEdit_Create($hGui, $sText, $nRichEditOffset, $nRichEditOffset + $nRichEditOffsetTop, $nGUI_W - $nRichEditOffset * 2, $nGUI_H - $nRichEditOffset * 2 - $nRichEditOffsetTop - 24, BitOR($ES_MULTILINE, $ES_READONLY, $WS_HSCROLL, $WS_VSCROLL))
_GUICtrlRichEdit_SetSel($hRichEdit, 0, -1, True)
_GUICtrlRichEdit_SetFont($hRichEdit, Default, 'Courier New')

GUISetState()

; work with GUI
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
        Case $cWrap
            ; Store current stream
            Local $bStream = _GUICtrlRichEdit_StreamToVar($hRichEdit)
            ; Empty RichEdit
            _GUICtrlRichEdit_SetSel($hRichEdit, 0, -1)
            _GUICtrlRichEdit_ReplaceText($hRichEdit, "")
            ; Toggle wrap
            $bWrap = Not $bWrap
            ; Destroy and recreate RichEdit with the necessary styles
            _GUICtrlRichEdit_Destroy($hRichEdit)
            If $bWrap Then
                $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", $nRichEditOffset, $nRichEditOffset + $nRichEditOffsetTop, $nGUI_W - $nRichEditOffset * 2, $nGUI_H - $nRichEditOffset * 2 - $nRichEditOffsetTop - 24, BitOR($ES_MULTILINE, $ES_READONLY, $WS_VSCROLL))
            Else
                $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", $nRichEditOffset, $nRichEditOffset + $nRichEditOffsetTop, $nGUI_W - $nRichEditOffset * 2, $nGUI_H - $nRichEditOffset * 2 - $nRichEditOffsetTop - 24, BitOR($ES_MULTILINE, $ES_READONLY, $WS_HSCROLL, $WS_VSCROLL))
            EndIf
            ; Reload the stream
            _GUICtrlRichEdit_StreamFromVar($hRichEdit, $bStream)
    EndSwitch
WEnd
M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 1 year later...

I know this is an old post but I figured it out after @orbs requested I look at this from another topic. Initially I couldn't figure it out either. I thought the $WS_HSCROLL was word wrap, and it very well may be for a regular edit control, but for richedit there is an actual word wrap option. using EM_SETTARGETDEVICE you can enable/disable word wrap

#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>

; build GUI
Global Const $nGUI_MaxW = 500, $nGUI_MaxH = 100
Global $nGUI_W = 720, $nGUI_H = 500, $nRichEditOffset = 10, $nRichEditOffsetTop = 30
Global $nToolbarHeight = $nRichEditOffsetTop
Global $hGui = GUICreate('RichEdit wrap/unwrap test', $nGUI_W, $nGUI_H, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_SYSMENU))
GUISetBkColor(0xCCDDEE)
; - toolbar ; ** requires an extra lower contour if main rich edit is not docked to edges
Global $gToolbarBackground = GUICtrlCreateLabel('', 0, 0, $nGUI_W, $nToolbarHeight)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT))
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_DISABLE)
Global $gToolbarBackgroundContour = GUICtrlCreateLabel('', 0, $nToolbarHeight+1, $nGUI_W, 1)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKRIGHT, $GUI_DOCKHEIGHT))
GUICtrlSetBkColor(-1, 0)
GUICtrlSetState(-1, $GUI_DISABLE)
; -- wrap/unwrap
Global $bWrap = False
Global $gWrap = GUICtrlCreateCheckbox('Wrap', 3, 3, 48, 24, $BS_PUSHLIKE)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKTOP, $GUI_DOCKLEFT, $GUI_DOCKSIZE))
; - main
Global $hRichEdit = _GUICtrlRichEdit_Create($hGui, 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz', $nRichEditOffset, $nRichEditOffset + $nRichEditOffsetTop, $nGUI_W - $nRichEditOffset * 2, $nGUI_H - $nRichEditOffset * 2 - $nRichEditOffsetTop - 24, BitOR($ES_MULTILINE, $WS_HSCROLL, $WS_VSCROLL))
_GUICtrlRichEdit_SetSel($hRichEdit, 0, -1, True)
_GUICtrlRichEdit_SetFont($hRichEdit, Default, 'Courier New')
GUISetState()
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO")
GUIRegisterMsg($WM_SIZE, "_WM_SIZE")
; work with GUI
Global $iMsg = 0
While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($hRichEdit)
            Exit
        Case $gWrap
            $bWrap = Not $bWrap
            ConsoleWrite(_GUICtrlRichEdit_WordWrap($hRichEdit, $bWrap) & @LF)
    EndSwitch
WEnd

Func _GUICtrlRichEdit_WordWrap($hWnd, $bEnable = True)
    If (IsHWnd($hWnd) = False) Then Return SetError(1, 0, False)

    DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", $EM_SETTARGETDEVICE, "wparam", 0, "lparam", Not $bEnable)

    If (@Error) Then Return SetError(2, @extended, False)

    Return True
EndFunc

This topic gave me the answer.

Edited by InunoTaishou
Link to comment
Share on other sites

  • Moderators

InunoTaishou,

Good job!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 weeks later...

@InunoTaishou, thank you so much for this.

have you any idea how to get the wrap status of a RichEdit control? i recon if the UDF _GUICtrlRichEdit_SetWrap() is to be created, it would probably need to be accompanied by _GUICtrlRichEdit_GetWrap(). not that i mind so much, since i control the wrap status; but just in case...

i looked at _GUICtrlRichEdit_GetParaAttributes() and _GUICtrlRichEdit_GetParaAlignment() but they don't provide it.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

I can give it a go when I got some free time. Just some quick googling you're not going to find what you want with any of the autoit richedit functions

https://msdn.microsoft.com/en-us/library/aa313357(v=vs.60).aspx

SetTargetDevice works with the dc of the richedit controls, setting the line width of the WYSIWYG formatting. So, we'll have to figure out how to get the current WYSIWYG options and check the line width.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...