Jump to content

Append text to the last line of an editbox


Angel
 Share

Recommended Posts

Hi guys,

is there a simple (or even a complex :whistle: ) way to append text to the end of an edit box, regardless of the caret position? I want to be able to do this without scrolling down to the bottom as I want to be able to append some text while the user is looking at the top of the edit box.

I currently use the following code to append the text:

GUICtrlSetData ($logCtrlId, $text & @CRLF, 1)

Right now, if the user clicked somewhere on the Edit box, changing the caret position from the end to some other part in the middle of the text, the next time I append some text it is added where the caret position is. Instead I'd like to always append the text to the last line of the edit box.

Is this possible?

Thanks,

Angel

Link to comment
Share on other sites

I would think this would work:

GUICtrlSetData ($logCtrlId, GUICtrlRead ($logCtrlId) & $text & @CRLF, "")
That would just overwrite the contents of the control with the old contents plus the new string, right? The problem is that it seems that that would change the "position" (the scroll) so the user could not be reading the contents of the edit box while the script is updating it. Also, the edit box contains a huge amount of data, and is updated constantly, so I fear that the performance of the GUI would be pretty bad if I did that...

The solution that I am looking for is to have some way of moving the caret to the end of the editbox and then appending the new data into the edit box as I was doing before.

I know that you can change the caret position using one of the EditBox User functions, but I don't konw how to get the position of the last line in the edit box. Is there some way to do that?

Angel

Link to comment
Share on other sites

  • Moderators

I don't see you being able to do that without something like ControlSend()... and I've not tested that either.

Edit:

Looks like there's a function for everything but _GUICtrlEditAddLine :whistle: Ohhhh Gary ... :)

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I don't see you being able to do that without something like ControlSend()... and I've not tested that either.

Edit:

Looks like there's a function for everything but _GUICtrlEditAddLine :whistle: Ohhhh Gary ... :)

Where did you see that function? I can't find it in the "GuiEdit Management" section of the User Defined functions in the help file of the latest version (v3.2.0.1)!

Angel

Link to comment
Share on other sites

  • Moderators

Where did you see that function? I can't find it in the "GuiEdit Management" section of the User Defined functions in the help file of the latest version (v3.2.0.1)!

Angel

Re-Read what I typed... I typed, everything but...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I know that you can change the caret position using one of the EditBox User functions, but I don't konw how to get the position of the last line in the edit box. Is there some way to do that?

To get the last line you can used _GUICtrlEditLineCount($h_Edit)
AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line
Link to comment
Share on other sites

Re-Read what I typed... I typed, everything but...

Sorry, I did not understand you. As you can guess English is not my first language! :P

I managed to do this by using _GUICtrlEditLineCount. I'll try to post the solution tomorrow (hopefully I'll remember!). But I did not manage to avoid the control from scrolling down :nuke:

It is true that it seems that a _GuiCtrolEditAddLine is missing!

Thanks for the help!

Angel

Link to comment
Share on other sites

  • 5 months later...

Hate to revive a long dead thread (6 months, eep), but I'm having similar troubles with the very same thing, and was wondering if Angel (or anybody else for that matter) may have come up with something. I'm currently trying something along the lines of:

$end = StringLen(GUICtrlRead($editCtrl))
_GUICtrlEditSetSel($editCtrl, $end, $end)
GuiCtrlSetData($editCtrl, $line & @CRLF, 1)oÝ÷ Ùhbr(®Kw­¡§^·!÷n®)තg­«bú+«b¢x¬mè§
â¶×§¶ayçbµÊ'¶º%ʧ¢Ú'+kÊÚ©àzØ^qªÞ¶,ب»­iËnjYrv¶ jwfjG±é^rبØ^+l¢g­g¬Â)e¢÷«Â¸­{*.«Þ±é^"Ýý²÷«É©ç£(§©Ý#fÂëçm«mêÞßÛ'£²¶(®F«¢éݶ¬{¦Ûh¥êájÆëayçbµÊ'¶º%Âéߢ»n«^)^j÷¬¶®±êî¦åzÚ,rº%êZ×hÂv§v·v­¦ëZ²+wöÆ©¥æ«xº-zØb²Èh®Û®*m¶^춶­{Z´ý½æÞzxZ¾)঺é¬Â+ajëh×6#include <GUIConstants.au3>
#include <GUIEdit.au3>
GUICreate('', 400, 300)
$buttonCtrl = GUICtrlCreateButton('Click', 0, 0, 40, 20)
$editCtrl = GUICtrlCreateEdit('', 0, 20, 400, 280, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
GUISetState()

While 1
    $gm = GUIGetMsg()
    Switch $gm
        Case $buttonCtrl
            GuiCtrlSetData($editCtrl, '')
            For $i = 1 to 200
                $end = StringLen(GUICtrlRead($editCtrl))
                _GUICtrlEditSetSel($editCtrl, $end, $end)
                GuiCtrlSetData($editCtrl, 'Line ' & $i & @CRLF, 1)
                Sleep(10)
            Next
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

If you run that script, then click the "Click" button, and then try to click and drag in the edit control while it's writing, you'll see that it will overwrite some of the output.

Gary really does need to make a GUICtrlEditAddLine. :whistle:

Link to comment
Share on other sites

from my project (work on normal edit too)

;
 
====================================================================================================
; Description ..: Append some text to the control
; Parameters ...: $hWnd         - Handle to the control
;                 $iText        - Text to append
;                 $hLine         - insert the @crlf at the end (default = True)
; Return values : Returns the index of the first new image if successful, or -1 otherwise
; Author .......: Yoan Roblet (Arcker)
; Notes ........:
; ====================================================================================================
Func _RichEdit_AddLine($hWnd, $iText, $hLine = True)
    Local $hTextLengh
    $hTextLengh = _API_SendMessage ($hWnd, $WM_GETTEXTLENGTH, 0, 0);
    _API_SendMessage ($hWnd, $EM_SETSEL, $hTextLengh, $hTextLengh);
    If $hLine Then
        _GUICtrlEditReplaceSel($hWnd, 1, $iText & @CRLF);
    Else
        _GUICtrlEditReplaceSel($hWnd, 1, $iText);
    EndIf
EndFunc   ;==>_RichEdit_AddLine

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
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...