Jump to content

RichEdit Text Height


Sticky
 Share

Recommended Posts

I am attempting to have any text that is not completely visible at the bottom of a richedit control with no scrollbars to jump to the next available richedit control. I believe I've figured out every proof of concept to get this going, except for being able to calculate when text has hit the bottom of the current control.

I have found _GuiCtrlRichEdit_SetSpaceUnit("pt"), but am unable to see a way to use this to my benefit. I've also found _GUICtrlRichEdit_GetLineCount($hWnd) but since I do not know the height of each individual line, it doesn't do what I need. Keep in mind that there can be multiple fonts and multiple sizes.

Maybe there's a way to hook into how the richedit control generates a vertical scrollbar only when needed?

You might be asking why I'm wanting to do this; I'm creating an easy method of displaying lyrics for a choir. The director copy pastes into one richedit control, and it automatically creates as many richedits as needed to hold all the text with no scrollbars in order to be later shown "slide" by "slide". The slides will just be a zoomed version [_GUICtrlRichEdit_SetZoom($hRichEdit, 250)] of each richedit control in order.

Link to comment
Share on other sites

Thanks for your input James! Correct me if I'm wrong, but if you change the size or color with an edit control, then the entire control receives the formatting, and not just selected text, right?

The choir director will be using different font colors and sizes to indicate which section in the choir sings what, on the same "slide".

Link to comment
Share on other sites

Maybe if I go character by character, get the height of each one based on its font size, and keep track of the heighest character on each line... sounds like it might cause some massive calculations every single time a change happens...

Any other thoughts or solutions?

Link to comment
Share on other sites

  • Moderators

Sticky,

This is one way to do realise you have come to the end of a RichEdit control: :(

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

Opt('MustDeclareVars', 1)

Global $hGUI, $hRichEdit, $lblMsg

Main()

Func Main()
    Local $iMsg
    $hGui = GUICreate("Test", 320, 350)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $lblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
    GUISetState()

    _GuiCtrlRichEdit_SetText($hRichEdit, "Line 1")
    For $i = 2 To 20
        If _TextInsertTest(@CRLF & "Line " & $i) Then
            MsgBox(0, "Full", "This one is full!")
            ExitLoop
        EndIf
        Sleep(250)
    Next

    While 1
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                GUIDelete()
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Main

Func _TextInsertTest($sText)

    ; Count the @CRLFs
    StringReplace(_GUICtrlRichEdit_GetText($hRichEdit, True), @CRLF, "")
    Local $iLines = @extended
    ; Adjust the text char count to account for the @CRLFs
    Local $iEndPoint = _GUICtrlRichEdit_GetTextLength($hRichEdit, True, True) - $iLines
    ; Add new text
    _GUICtrlRichEdit_AppendText($hRichEdit, $sText)
    ; Check on the scroll position
    Local $aPos = _GUICtrlRichEdit_GetScrollPos($hRichEdit)
    If $aPos[1] > 0 Then
        ; Select text between old and new end points
        _GuiCtrlRichEdit_SetSel($hRichEdit, $iEndPoint, -1)
        ;Sleep(1000)
        ; Delete it
        ControlSend($hGUI, "", $hRichEdit, "{DELETE}")
        ;Sleep(1000)
        Return True
    Else
        Return False
    EndIf

EndFunc

A fair amount to do to get it working as you need it, but the proof of concept is there. :graduated:

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

Thank you for the help Melba!

I noticed one way to get around the detection of text running out of the richedit control. If you write a few lines, then return to the top, write a few more, and continue repeating returning to the top, it will never detect text running off the screen.

Is there maybe a way to detect when a vertical scroll bar shows up in the control?

Link to comment
Share on other sites

Thank you for the help Melba!

I noticed one way to get around the detection of text running out of the richedit control. If you write a few lines, then return to the top, write a few more, and continue repeating returning to the top, it will never detect text running off the screen.

Is there maybe a way to detect when a vertical scroll bar shows up in the control?

One way that might be helpful is to send messages to the RichEdit control.

The EM_CHARFROMPOS message retrieves information about the character

closest to a specified point in the client area of an edit control so you can use the top or bottom coords.

The EM_EXLINEFROMCHAR message determines which

line contains the specified character in a rich edit control.

Sending the EM_GETFIRSTVISIBLELINE message to a multi-line edit control

finds out which line is the first line visible.

This is the line that is currently displayed at the top of the control.

Maybe EM_GETSCROLLPOS will give you an idea of the scroll bar. See what the return is when the scroll bar is there or not.

Or if you enable EN_REQUESTRESIZE then you can detect when the rich edit needs to be resized and if the size required is larger than current then the scroll bar will be there I assume.

To receive EN_REQUESTRESIZE notification codes, you must enable the notification by using the EM_SETEVENTMASK message.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • Moderators

Sticky,

This detects when the control is full even if you add the text at the beginning of the existing text: :(

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

Opt('MustDeclareVars', 1)

Global $hGUI, $hRichEdit, $lblMsg

Main()

Func Main()
    Local $iMsg
    $hGui = GUICreate("Test", 320, 350)
    $hRichEdit = _GUICtrlRichEdit_Create($hGui, "", 10, 10, 300, 220, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
    $lblMsg = GUICtrlCreateLabel("", 10, 235, 300, 60)
    GUISetState()

    _GuiCtrlRichEdit_SetText($hRichEdit, "Line 1" & @CRLF)
    ControlSend($hGUI, "", $hRichEdit, "^{PGUP}")
    For $i = 2 To 20
        _GUICtrlRichEdit_InsertText($hRichEdit, "Line " & $i & @CRLF)
        ControlSend($hGUI, "", $hRichEdit, "^{PGUP}")
        If _TextInsertTest() Then
            MsgBox(0, "Full", "This one is full!")
            ExitLoop
        EndIf
        Sleep(250)
    Next

    While 1
        $iMsg = GUIGetMsg()
        Select
            Case $iMsg = $GUI_EVENT_CLOSE
                GUIDelete()
                Exit
        EndSelect
    WEnd
EndFunc   ;==>Main

Func _TextInsertTest()

    ; Move to end of text
    ControlSend($hGUI, "", $hRichEdit, "^{END}")
    Sleep(1000) ; Just for demo
    ; Check on the scroll position
    Local $aPos = _GUICtrlRichEdit_GetScrollPos($hRichEdit)
    If $aPos[1] > 0 Then
        ; Delete last line entered
        _GUICtrlRichEdit_Undo($hRichEdit)
        ; Move back to top
        ControlSend($hGUI, "", $hRichEdit, "^{HOME}")
        Return True
    Else
        ControlSend($hGUI, "", $hRichEdit, "^{HOME}")
        Return False
    EndIf

EndFunc

Although if you are filling a RichText control with lines from a song, I cannot see why you would want to add the new lines at the top. :graduated:

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

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...