Sticky Posted November 19, 2010 Share Posted November 19, 2010 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 More sharing options...
James Posted November 19, 2010 Share Posted November 19, 2010 Sticky, My question to you is; why do you need a Richtext control? Because you need the font stuff? You can pragmatically set the text colour and size of a normal edit control. James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Sticky Posted November 19, 2010 Author Share Posted November 19, 2010 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 More sharing options...
Sticky Posted November 20, 2010 Author Share Posted November 20, 2010 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 More sharing options...
Moderators Melba23 Posted November 20, 2010 Moderators Share Posted November 20, 2010 Sticky,This is one way to do realise you have come to the end of a RichEdit control: expandcollapse popup#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 EndFuncA fair amount to do to get it working as you need it, but the proof of concept is there. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Sticky Posted November 23, 2010 Author Share Posted November 23, 2010 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 More sharing options...
martin Posted November 23, 2010 Share Posted November 23, 2010 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 More sharing options...
Moderators Melba23 Posted November 23, 2010 Moderators Share Posted November 23, 2010 Sticky, This detects when the control is full even if you add the text at the beginning of the existing text: expandcollapse popup#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. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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