Jump to content

_GUICtrlEdit_AppendText freezes gui


Recommended Posts

  • Moderators

TheAutomator,

I thought that you were happy with the suggested solution posted by AutoBert, so I put this on the back burner - I now see that you are not. But real life has been rather demanding of my time lately - I should have some time to look at it again later this week.

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

Ok found the problem.  To solve it, follow those steps :

1- copy the UDF GuiEdit.au3 from the AutoIt\Include to your script folder

2- rename it GUIEditEX.au3

3- remove the read only property of the file

4- edit the file and replace in the Func _GUICtrlEdit_AppendText : _SendMessage by _SendMessageA

5- save the file

6- replace in your script the #include <GUIEdit.au3> by #include "GUIEditEX.au3"

7- run your script

8- enjoy

 

Tested both on win7 and win10

Edited by Nine
Link to comment
Share on other sites

19 hours ago, Melba23 said:

TheAutomator,

I thought that you were happy with the suggested solution posted by AutoBert, so I put this on the back burner - I now see that you are not. But real life has been rather demanding of my time lately - I should have some time to look at it again later this week.

M23

Yes, i replied to fast on him..
Thanks for taking your time to look back at it :)

Regards,

TheAutomator

Link to comment
Share on other sites

Nine,

Nice! Gonna test this when I'm home from work :)

EDIT -> after testing:

It seems to behave strange now, doesn't append some characters anymore:

Global $clear = False
func WRITE($message)
    if $clear then
        $clear = False
    else
        _guictrledit_appendtext($console, '>>>' & @crlf) ; only types '>', no crlf also...
    endif
    ADD($message)
endfunc

Regards,
TheAutomator

Edited by TheAutomator
Link to comment
Share on other sites

Replace the func in GUIEditEX.au3 with this code :

Func _GUICtrlEdit_AppendText($hWnd, $sText)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    Local $iLength = _GUICtrlEdit_GetTextLen($hWnd)
    _GUICtrlEdit_SetSel($hWnd, $iLength, $iLength)
    Local $tString = DllStructCreate ("char[" & StringLen ($sText)+1 & "]")
    DllStructSetData ($tString, 1, $sText & chr (0))

    _SendMessageA($hWnd, $EM_REPLACESEL, True, DllStructGetPtr($tString), 0, "wparam", "lparam")
EndFunc   ;==>_GUICtrlEdit_AppendText

 

Link to comment
Share on other sites

I played with this problem too and tried this workaround but the result was the same, so this "fix" doesn't work, just for info here:

Func _GUICtrlEdit_AppendText($hWnd, $sText)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    Local $sOrig = _GUICtrlEdit_GetText($hWnd)
    _GUICtrlEdit_SetText($hWnd, $sOrig & $sText)
EndFunc   ;==>_GUICtrlEdit_AppendText2

 

Edited by Zedna
Link to comment
Share on other sites

Link to comment
Share on other sites

17 hours ago, Nine said:

Seems my last patch is working well.  Tested with multiple text lengths including those of OP, both on Win7 and Win10.  No flaw so far,..

For now it seems to work well, thanks for that!
What did you do exactly? i see sendmessageA and dllcalls getting involved? 🤔

[EDIT]

Bad news.. 😕
I was tinkering around with it and suddenly the gui froze again while appending some text...

I don't know exactly what text it was, it was a test using random strings from a file.

Regards,
TheAutomator

Edited by TheAutomator
Link to comment
Share on other sites

write(FileRead(@ScriptDir & '\a.txt'))
GUICtrlSetData($console, '')
$clear = True
add(FileRead(@ScriptDir & '\a.txt'))
read()
write('[[[done]]]')
ergljnemr negn mqegnmqe ,
regergnoaerngpoaergn
ergojnaeoge on on on o n o  
 
  ergergae
  
ergaergk.

ergraeg5457erg758,,;7,9:87
$^m$tgmù^µrsgm^$
^ergml^qpgregre;gg

ergk,nqerpginjo^qerhg oirheo h oubh eborgu 
erognq^oi o  oinoi no no in oi   o negq
geogpe

gqeporgjpaegjpârgje^ùpargee,
a
b
v
c
x
w
e1
12
123
12364
123456465
47879
8798798798798
.
azzerttyuuiipp12345798

example of the script part i used for testing + text file called 'a.txt'

Aantekening 2020-02-11 115123.jpg

Edited by TheAutomator
Link to comment
Share on other sites

Seems there is some kind of a bug in Win10.  It may be related to the previous one, but I didn't test it.  Someone should report it to MicroSoft.

Anyway, I think I have found a workaround.  You must use the patch that I made and change your function to this :

Func ADD($message)
  Local $char
  For $i = 1 To StringLen($message)
    $char = StringMid($message, $i, 1)
    If Asc ($char) = 13 Then $char &= @LF
    If Asc ($char) = 10 Then ContinueLoop
    _GUICtrlEdit_AppendText($console, $char)
    Sleep(50)
  Next
EndFunc   ;==>ADD

The message gets stuck from time to time when @CR is sent alone. chepa.gif

I will let @Melba23 decide how he would like to manage it.

Link to comment
Share on other sites

  • Moderators

TheAutomator,

As promised I have been playing around with this problem again over the past few days and have not changed my original conclusion (see my earlier post) that the problem seems to arise after clearing the edit using GUICtrlSetData and then trying to use _GUICtrlEdit_AppendText to add text which includes @CR characters. if you do this the script freezes at some indeterminate (as far as I can see) instance of a @CR within the new text being appended - although the freeze is repeatable at the same point for a given text.  This appears only to be a problem when using Win 10 - so like Nine I suspect that a subtle change within the editbox implementation has caused this, but I have no idea just what.

I have played about with various ways of emptying the editbox before appending the new text - such as not mixing native and UDF functions (often a recipe for disaster) and using _GUICtrlEdit_SetSel and _GUICtrlEdit_ReplaceSel to clear the edit - but the only reliable way to avoid the problem seems to be to delete and recreate the entire control - which might appear a bit of an overkill but does at least seem to resolve the problem:

#include <guiconstantsex.au3>
#include <buttonconstants.au3>
#include <windowsconstants.au3>
#include <guiedit.au3>

Opt("TrayIconDebug", 1)

HotKeySet('{esc}', 'quit')

Const $form = GUICreate('TypingError', 600, 400) ;, Default, Default, BitOR($gui_ss_default_gui, $ws_maximizebox, $ws_sizebox, $ws_thickframe, $ws_tabstop))
$console = GUICtrlCreateEdit('loading...', 10, 10, 581, 341, BitOR($es_autovscroll, $es_readonly, $es_wantreturn, $ws_vscroll)) ;, 0)
Const $user = GUICtrlCreateInput('', 10, 360, 521, 30) ; , Default, 0)
Const $send = GUICtrlCreateButton('send', 540, 360, 51, 31, BitOR($es_uppercase, $bs_defpushbutton, $ws_disabled))

GUISetState(@SW_SHOW)

Global $clear = False

write(FileRead(@ScriptDir & '\a.txt'))
$clear = True
write(FileRead(@ScriptDir & '\a.txt'))
read()
write('[[[done]]]')

Func WRITE($message)
    If $clear Then
        ; Delete existing edit control and recreate a new empty one <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        GUICtrlDelete($console)
        $console = GUICtrlCreateEdit('', 10, 10, 581, 341, BitOR($es_autovscroll, $es_readonly, $es_wantreturn, $ws_vscroll))
        $clear = False
    Else
        _GUICtrlEdit_AppendText($console, @CRLF)
    EndIf
    ADD($message)
EndFunc   ;==>WRITE

Func ADD($message)
    For $i = 1 To StringLen($message)
        Sleep(50)
        _GUICtrlEdit_AppendText($console, StringMid($message, $i, 1))
    Next
EndFunc   ;==>ADD

Func READ()
    GUICtrlSetState($send, $gui_enable)
    While 1
        Switch GUIGetMsg()
            Case $gui_event_close
                Exit
            Case $send
                GUICtrlSetState($send, $gui_disable)
                Local $answer = GUICtrlRead($user)
                GUICtrlSetData($user, '')
                Return $answer
        EndSwitch
    WEnd
EndFunc   ;==>READ

Func QUIT()
    WRITE("goodbye...")
    Exit
EndFunc   ;==>QUIT

Sorry that I cannot yet pin the problem down any closer - and that we need to use such an inelegant workaround. I will keep poking away at the problem and see if anything new comes up.

M23

Edit: Just to add that amending the _AppendText function did not work for me at all.

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

  • Moderators

TheAutomator,

The Devs have looked into the problem and, as Nine and I reported, it appears that Win 10 edit controls do not like having single @CR characters passed to them - so we can put this problem down to MS and not AutoIt.

To enable you to use the _GUICtrlEdit_AppendText function we suggest using something like this:

Func ADD($message)
    For $i = 1 To StringLen($message)
        Sleep(50)
        ; Look for @CR and @LF
        If StringMid($message, $i, 1) = @CR Or StringMid($message, $i, 1) = @LF Then
            ; If @CR then check it is followed by @LF and send @CRLF in one call and pass over the trailing @LF         
            If StringMid($message, $i, 2) = @CRLF Then $i += 1
            _GUICtrlEdit_AppendText($console, @CRLF)
        Else
            _GUICtrlEdit_AppendText($console, StringMid($message, $i, 1))
        EndIf
    Next
EndFunc   ;==>ADD

That works for us on all the examples you posted.

We will now consider whether we need to adjust the Help file to reflect this new behaviour of the edit control under Win 10.

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

@Melba23 would this following example will fit the same feature:

Func ADD($message)
    _GUICtrlEdit_AppendText($console, StringRegExpReplace($message, '\R', @CRLF) & @CRLF)
EndFunc   ;==>ADD

?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

@mLipok No. OP wants to send single char at a time, like those typewriters way back. The problem is not to send a message containing @CR alone.  The problem is to send this single char @CR with a delay before sending his buddy @LF.

Link to comment
Share on other sites

Thanks for clarifing.

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

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