Jump to content

Add text to Edit box and scroll it down


Likurg
 Share

Recommended Posts

Hello!

I have an edit box ( GUICtrlCreateEdit ), and I am logging there programm actions.

I made it read-only, but user still can place a caret there.

I need to append text to this edit box and scroll it down to the end, so user

could see last logs. I tried two options, first one is:

GUICtrlSetData($statusTextField, @CRLF & "Build started", 1)

in this case everything works fine, until user will place a caret in different place on the edit box,

so the text will be inserted there, not to the end.

The other options is:

GUICtrlSetData($statusTextField, GUICtrlRead(statusTextField) & @CRLF & "Build started")

In this case last logs are always appended to the end, but edit box is not scrolled down.

Any help would be highly appreciated!

Edited by Likurg
Link to comment
Share on other sites

  • Moderators

Likurg,

This will place the caret at the end of the current text and scroll down to bring it into view:

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#Include <GUIEdit.au3>
#Include <ScrollBarConstants.au3>

$sText = "Line 1" & @CRLF & _
         "Line 2" & @CRLF & _
         "Line 3" & @CRLF & _
         "Line 4" & @CRLF & _
         "Line 5" & @CRLF & _
         "Line 6" & @CRLF & _
         "Line 7" & @CRLF & _
         "Line 8" & @CRLF & _
         "Line 9"

$hGUI = GUICreate("Test", 500, 500)

$hEdit = GUICtrlCreateEdit($sText & @CRLF & $sText & @CRLF & $sText, 10, 10, 200, 200, BitOr($GUI_SS_DEFAULT_EDIT, $ES_READONLY))

$hButton = GUICtrlCreateButton("Add", 10, 250, 80, 30)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
            $iEnd = StringLen(GUICtrlRead($hEdit))
            _GUICtrlEdit_SetSel($hEdit, $iEnd, $iEnd)
            _GUICtrlEdit_Scroll($hEdit, $SB_SCROLLCARET)

            GUICtrlSetData($hEdit, @CRLF & "New line inserted", 1)

    EndSwitch

WEnd

I hope it is what you wanted. :mellow:

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

  • Moderators

Likurg,

Sorry, I forgot to add that you can put the caret anywhere in the text and it will still add the new text at the bottom.

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

  • Moderators

playlet,

Sorry, but that is not what the OP wanted. :mellow:

In your script you can place the caret in the existing word and the new information is inserted at that point. What the OP wanted was to ensure that the new test was added at the end and visible - hence the moving of the caret to the end with _GUICtrlEdit_SetSel and then scrolling down with _GUICtrlEdit_Scroll.

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

  • Moderators

Playlet,

No problem. :mellow:

My old maths teacher used to say before every exam: "READ THE QUESTION!". I still try and follow his advice - although I am the first to admit that I do not do so every time. :(

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

I'm having the same issue here. Here is a test script to append text to the end of a Edit Control. All it is doing is overwriting the line again and again.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GUIEdit.au3>
#Include <ScrollBarConstants.au3>
GUICreate("Test", 803, 502, 192, 124, $WS_POPUPWINDOW)
$Edit = GUICtrlCreateEdit("", -1, -1, 823, 509, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
GUISetState(@SW_SHOW)
GUICtrlSetBkColor($Edit, 0x000000)
GUICtrlSetColor($Edit, 0x00ff00)

$Inventory = _FileListToArray_Recursive(@ScriptDir & "", '*', 1, 2, True)

For $i = 1 To (UBound($Inventory) -1)
$iEnd = StringLen(GUICtrlRead($Edit))
_GUICtrlEdit_SetSel($Edit, $iEnd, $iEnd)
_GUICtrlEdit_Scroll($Edit, $SB_SCROLLCARET)
GUICtrlSetData($Edit, @CRLF & $Inventory[$i])
Next

While 1
$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func _FileListToArray_Recursive($sPath, $sFilter = "*", $iRetItemType = 0, $iRetPathType = 0, $bRecursive = False)
    Local $sRet = "", $sRetPath = ""
    $sPath = StringRegExpReplace($sPath, "[/]+z", "")
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[/ :> <|]|(?s)As*z") Then Return SetError(2, 2, "")
    $sPath &= "|"
    $sOrigPathLen = StringLen($sPath) - 1
    While $sPath
        $sCurrPathLen = StringInStr($sPath, "|") - 1
        $sCurrPath = StringLeft($sPath, $sCurrPathLen)
        $Search = FileFindFirstFile($sCurrPath & $sFilter)
        If @error Then
            $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
            ContinueLoop
        EndIf
        Switch $iRetPathType
            Case 1 ; relative path
                $sRetPath = StringTrimLeft($sCurrPath, $sOrigPathLen)
            Case 2 ; full path
                $sRetPath = $sCurrPath
        EndSwitch
        While 1
            $File = FileFindNextFile($Search)
            If @error Then ExitLoop
            If ($iRetItemType + @extended = 2) Then ContinueLoop
            $sRet &= $sRetPath & $File & "|"
        WEnd
        FileClose($Search)
        If $bRecursive Then
            $hSearch = FileFindFirstFile($sCurrPath & "*")
            While 1
                $File = FileFindNextFile($hSearch)
                If @error Then ExitLoop
                If @extended Then $sPath &= $sCurrPath & $File & "|"
            WEnd
            FileClose($hSearch)
        EndIf
        $sPath = StringTrimLeft($sPath, $sCurrPathLen + 1)
    WEnd
    If Not $sRet Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimRight($sRet, 1), "|")
EndFunc   ;==> Melba23's _FileListToArray_Recursive

Edit:

Nevermind forgot to add ", 1)" at end of GUICtrlSetData($Edit, @CRLF & $Inventory[$i])

Edited by rogue5099
Link to comment
Share on other sites

  • Moderators

Rogue5099,

You are missing a vital parameter: :oops:

GUICtrlSetData($Edit, @CRLF & $Inventory[$i], 1) ; <<<<<<<<<<< See it now?

M23

Edit:

That recursive search function has been much improved by the way - the latest version is in my sig. :bye:

Edited by Melba23

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

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GUIEdit.au3>
#Include <ScrollBarConstants.au3>
#include <RecFileListToArray.au3>
$Inventory = _RecFileListToArray(@UserProfileDir & "\", "*", 1, 1, 1, 0)
GUICreate("Test", 473, 502, -1, -1, $WS_POPUPWINDOW)
$Edit = GUICtrlCreateEdit("", -1, -1, 823, 509, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL, $ES_READONLY))
GUISetState(@SW_SHOW)
GUICtrlSetBkColor($Edit, 0x000000)
GUICtrlSetColor($Edit, 0x00ff00)

For $i = 1 To (UBound($Inventory) -1)
$iEnd = StringLen(GUICtrlRead($Edit))
_GUICtrlEdit_SetSel($Edit, $iEnd, $iEnd)
_GUICtrlEdit_Scroll($Edit, $SB_SCROLLCARET)
GUICtrlSetData($Edit, @CRLF & $Inventory[$i], 1)
Next

While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Thanks for the update on your RFLTA. Now I am guessing there is a cap on Edit box? How would I go around that? to list infinite characters? Let's just take above for example. Most data is stored in UserProfileDir (picture, music, TEMP FILES) caped Temp Files cause there are a lot usually. I know that you can exclude with your new UDF but I just want to know if you can increase Edit Box or use something else to list infinite number of characters.

Link to comment
Share on other sites

  • Moderators

Rogue5099,

Windows limits edit controls to about 32k characters by default - you can increase this by using GUICtrlSetLimit. :oops:

I have no idea what the absolute max value is but it is certainly not infinite. :bye:

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

  • Moderators

Rogue5099,

I love your Updated RFLTA speed

Thanks - I normally get complaints that it is too slow! :oops:

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