kitoy

Previous data is removed after using GUICtrlSetData

13 posts in this topic

I wanted to make a countdown timer without queueing the countdown message to the next line but the previous data is removed after using GUICtrlSetData. Any thoughts on how to display the previous data/message?

Here is an example:

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

Global $_main = GUICreate("", 501, 313, -1, -1)
Global $g_idMemo = GUICtrlCreateEdit("", 2, 2, 496, 274, $ES_AUTOVSCROLL + $ES_READONLY + $WS_VSCROLL)
GUICtrlSetData(-1, "")
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
GUICtrlSendMsg($g_idMemo, $EM_SETREADONLY, True, 0)
GUICtrlSetBkColor($g_idMemo, 0xFFFFFF)
GUICtrlSetCursor($g_idMemo, -1)
GUISetState(@SW_SHOW)

HotKeySet('{esc}', "_close")
Func _close()
    Exit
EndFunc   ;==>_close

Func MemoWrite($sMessage = "")
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

MemoWrite("test message 1")
Sleep(1000)
MemoWrite("test message 2")
Sleep(1000)
MemoWrite("test message 3")
Sleep(1000)

For $i = 5 to 0 Step -1
    GUICtrlSetData($g_idMemo, "Program will exit in "&$i&" seconds...")
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites



kitoy,

Use _GUICtrlEdit_AppendText - that way you add to the existing content rather then replacing it. Or else read the existing content, concatenate the required new text and then replace the old with the new. I would recommend the former.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Share this post


Link to post
Share on other sites

The latter works pretty nice though  :)

$previous = GuiCtrlRead($g_idMemo)
For $i = 5 to 0 Step -1
    GUICtrlSetData($g_idMemo, $previous & "Program will exit in "&$i&" seconds...")
    Sleep(1000)
Next

 

Share this post


Link to post
Share on other sites

For me I would either setup a popup with the timed message or place a label at the top of the GUI that appears instead of inserting the message into the edit control itself.

Share this post


Link to post
Share on other sites

Following Melba23's second solution in post #2, here is a modified example of post #1.
Note the convention of having all the user defined functions (UDFs) at the end of the script.

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

HotKeySet('{esc}', "_close")

Global $_main = GUICreate("", 501, 313, -1, -1)
Global $g_idMemo = GUICtrlCreateEdit("", 2, 2, 496, 274, $ES_AUTOVSCROLL + $ES_READONLY + $WS_VSCROLL)
;GUICtrlSetData(-1, "")
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
;GUICtrlSendMsg($g_idMemo, $EM_SETREADONLY, True, 0)
GUICtrlSetBkColor($g_idMemo, 0xFFFFE0)
GUICtrlSetCursor($g_idMemo, -1)
GUISetState(@SW_SHOW)

MemoWrite("test message 1")
Sleep(1000)
MemoWrite("test message 2")
Sleep(1000)
MemoWrite("test message 3")
Sleep(1000)

;Local $sEditText = ControlGetText($_main, "", $g_idMemo)
;Or
Local $sEditText = GUICtrlRead($g_idMemo)
For $i = 5 To 0 Step -1
    GUICtrlSetData($g_idMemo, $sEditText & "Program will exit in " & $i & " seconds...")
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func MemoWrite($sMessage = "")
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Func _close()
    Exit
EndFunc   ;==>_close

 

Share this post


Link to post
Share on other sites

Malkey,
Please explain the difference with my reply in post #3  :)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Well, that answers my problem. Thanks everyone for the help.

@mikell, @Malkey - both are the same but Malkey have another option.

;Local $sEditText = ControlGetText($_main, "", $g_idMemo)

I believe this is now closed?
Edit:  Found a new error.

Edited by kitoy

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

<...idiotic response deleted...>

I'll never respond to another one of these from my stupid phone.

Edited by kylomas

Forum Rules         Procedure for posting code

Share this post


Link to post
Share on other sites

Found some error when the lines are already to long. Once the countdown starts, it will go back to the very first line.

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

HotKeySet('{esc}', "_close")

Global $_main = GUICreate("", 501, 313, -1, -1)
Global $g_idMemo = GUICtrlCreateEdit("", 2, 2, 496, 274, $ES_AUTOVSCROLL + $ES_READONLY + $WS_VSCROLL)
;GUICtrlSetData(-1, "")
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
;GUICtrlSendMsg($g_idMemo, $EM_SETREADONLY, True, 0)
GUICtrlSetBkColor($g_idMemo, 0xFFFFE0)
GUICtrlSetCursor($g_idMemo, -1)
GUISetState(@SW_SHOW)

For $i = 1 to 20
    MemoWrite("test message " & $i)
    Sleep(100)
Next

;~ Local $sEditText = ControlGetText($_main, "", $g_idMemo)
;~ Or
Local $sEditText = GUICtrlRead($g_idMemo)
For $i = 10 To 0 Step -1
    GUICtrlSetData($g_idMemo, $sEditText & "Program will exit in " & $i & " seconds..." &@CRLF)
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func MemoWrite($sMessage = "")
    GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

Func _close()
    Exit
EndFunc   ;==>_close

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

I  (personally)  would use a listview as an alternative - and easier - way 

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

HotKeySet('{esc}', "_close")

Global $_main = GUICreate("", 501, 313, -1, -1)
;Global $g_idMemo = GUICtrlCreateEdit("", 2, 2, 496, 274, $ES_AUTOVSCROLL + $ES_READONLY + $WS_VSCROLL)

Global $g_idMemo = GUICtrlCreateListView(" ", 2, 2, 496, 274, $LVS_NOCOLUMNHEADER)
_GUICtrlListView_SetColumnWidth ($g_idMemo, 0, 470)

;GUICtrlSetData(-1, "")
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
;GUICtrlSendMsg($g_idMemo, $EM_SETREADONLY, True, 0)
GUICtrlSetBkColor($g_idMemo, 0xFFFFE0)
GUICtrlSetCursor($g_idMemo, -1)
GUISetState(@SW_SHOW)

For $i = 1 to 20
    $last_index = MemoWrite("test message " & $i)
    Sleep(100)
Next

;~ Local $sEditText = ControlGetText($_main, "", $g_idMemo)
;~ Or
; Local $sEditText = GUICtrlRead($g_idMemo)

For $i = 10 To 0 Step -1
   ; GUICtrlSetData($g_idMemo, $sEditText & "Program will exit in " & $i & " seconds..." &@CRLF)
    _GUICtrlListView_DeleteItem($g_idMemo, $last_index)
    $last_index = MemoWrite("Program will exit in " & $i & " seconds...")
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func MemoWrite($sMessage = "")
   ; GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
   $index = _GUICtrlListView_AddItem($g_idMemo, $sMessage )
   _GUICtrlListView_EnsureVisible($g_idMemo, $index)
  Return $index
EndFunc   ;==>MemoWrite

Func _close()
    Exit
EndFunc   ;==>_close

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

@mikell, thank you very much. This is really great. 

By the way, is it possible to insert the $last_index to the next line if the string exceeds to the column width. I don't want to use the horizontal scroll. I've been looking in the _GUICrtlListView functions or in the parameters but I couldn't find one.

For $i = 1 to 20
    $last_index = MemoWrite($i & ". The quick brown fox jumps over the red lazy dog. Exceeding the text out of the column width.")
    Sleep(100)
Next

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

As multiline listviewitems are impossible, it needs a workaround   :)
In the code below, the message is splitted in lines of 50 characters maxi - please look at the comments

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#Include <Array.au3>

HotKeySet('{esc}', "_close")

Global $_main = GUICreate("", 501, 313, -1, -1)
Global $g_idMemo = GUICtrlCreateListView(" ", 2, 2, 496, 274, $LVS_NOCOLUMNHEADER)
_GUICtrlListView_SetColumnWidth ($g_idMemo, 0, 470)

; this label disables clicks on the lisview, kind of 'readonly'
GUICtrlCreateLabel("", 2, 2, 470, 274)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState(-1, $GUI_ONTOP)

GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
GUICtrlSetBkColor($g_idMemo, 0xFFFFE0)
GUISetState(@SW_SHOW)

For $i = 1 to 20
    MemoWrite("test message " & $i)
    Sleep(100)
Next

$message = ". The quick brown fox jumps over the red lazy dog. Exceeding the text out of the column width."
; split the message to an array of lines, each line 50 chars max
$formatted = StringRegExp($message, '.{1,50}', 3)
;_ArrayDisplay($formatted)
For $i = 0 to UBound($formatted)-1
   MemoWrite($formatted[$i])
    Sleep(100)
Next

; this will display an empty line (looks like a @crlf)
MemoWrite()  

; this one is needed because it will be deleted by the first _GUICtrlListView_DeleteItem to come
$last_index = MemoWrite("will be deleted")  

For $i = 5 To 0 Step -1
    _GUICtrlListView_DeleteItem($g_idMemo, $last_index)
    $last_index = MemoWrite("Program will exit in " & $i & " seconds...")
    Sleep(1000)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func MemoWrite($sMessage = "")
   $index = _GUICtrlListView_AddItem($g_idMemo, $sMessage )
   _GUICtrlListView_EnsureVisible($g_idMemo, $index)
  Return $index
EndFunc   ;==>MemoWrite

Func _close()
    Exit
EndFunc   ;==>_close

 

Edited by mikell

Share this post


Link to post
Share on other sites

#13 ·  Posted

Thank you so much @mikell.

Share this post


Link to post
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

  • Similar Content

    • kashamalasha
      How to put formatted text via GUICtrlSetData to native Edit field
      By kashamalasha
      Hello.
      Could you help me find the answer for my issue. I'm trying to set fomatted data wich is selected from SQL to GUICtrlCreateEdit field.
      And the GUICtrlSetData function is inserting it in one line. But when I'm trying to do the same using MsgBox the data looks fine.
      I'm trying to not use _GUICtrlRichEdit UDF.
      Thanks in advance. Here is my test code.
      #include <GUIConstants.au3> #include <GUIListBox.au3> #include <SQLite.au3> #include <SQLite.dll.au3> Opt("GUIOnEventMode", 1) $hMainGUI = GUICreate("Test", 520, 240) $hListBox = _GUICtrlListBox_Create($hMainGUI, "", 10, 10, 180, 80) $hEdit = GUICtrlCreateEdit("", 10, 80, 500, 150) GUISetState(@SW_SHOW, $hMainGUI) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") Local $hQuery, $aRow _SQLite_Startup() $hDB = _SQLite_Open('MyDB.sqlite') _SQLite_Query(-1, "SELECT ID ||"". "" || Name FROM Templates ORDER BY ID;", $hQuery) While _SQLite_FetchData($hQuery, $aRow) = $SQLITE_OK _GUICtrlListBox_AddString($hListBox, $aRow[0]) WEnd GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSE_Button") While 1 Sleep(100) WEnd Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox) $hWndFrom = $lParam $iIDFrom = BitAND($wParam, 0xFFFF) ; Low Word $iCode = BitShift($wParam, 16) ; Hi Word Switch $hWndFrom Case $hListBox, $hWndListBox Switch $iCode Case $LBN_DBLCLK Select_Template(_GUICtrlListBox_GetCurSel($hListBox) + 1) Return 0 EndSwitch EndSwitch EndFunc ;==>_WM_COMMAND Func CLOSE_Button() _SQLite_Close() _SQLite_Shutdown() Exit EndFunc ;==>CLOSE_Button Func Select_Template($sListItem) _SQLite_QuerySingleRow($hDB, _ "SELECT Content " & _ "FROM Templates " & _ "WHERE ID = " & $sListItem & ";", $aRow) ;~ MsgBox(64, "Test: " & $sListItem, $aRow[0]) GUICtrlSetData($hEdit, $aRow[0]) WinSetTitle($hMainGUI, "", "Test: " & $sListItem) EndFunc ;==>Select_Template  


    • Reizvoller
      GuiCtrlCreateEdit & GuiCtrlSetData Question! :)
      By Reizvoller
      Hello!
      When utilizing GUICtrlSetData to edit what is displayed in a GUICtrlCreateEdit field, is there a way to just make it write new lines rather than clearing what's there and writing the new information?
      For example ... 
      GUICtrlSetData ($editField, "Line one"&@CRLF , "") GUICtrlSetData ($editField, "Line two"&@CRLF , "") GUICtrlSetData ($editField, "Line three"&@CRLF , "") What happens now if those three things run one after another, the Edit field displays "Line One" , then that is replaced with "Line Two" and so on with the previous information disappearing and the subsequent taking its place. I'd like for it to say all three, one after another. Any documents on how I may accomplish this?
      Thanks!
      -Reiz
    • Rfsvieira
      Function priority by timer
      By Rfsvieira
      Hello, i havê been reading, and thinking.. Im on my tablet só i WLL try explain what im trying to do....
      Will havê an GUI with 8 timer input that havê to set timer, but wen our if 2 our more ends at some time it havê to run 1, then outher , then outher
      Timer 1, - input 5 minutes, timer 2 - input 10, timer 3 input 15, timer 4 - input 8,......
      At some time,  timer 1 will end ate some time of timer 2 / then it at some time will end at some time timer 2 and 3 
      How i said that wen it happpens first is 2 then 1, then outhers and if 1 is done then 1st is 3, will have more than 9 input boxes that can happen it end at some time, imagine if wen timer 1= 0 function1(), then after end funciona start countdown again, if timer 2 = 0 run function2(), then after end function2 start contdoen again, if both =0 at some time first run 1 then 2, and if wen ends 1, 2,3,4 are =0 :-( :-( :-(  im lost
      This work…???
       
      thank you!
       
      Thanks for time, any ideas??? 
       
    • Rfsvieira
      Gui + Combobox setdata from other comboboxs choices
      By Rfsvieira
      Hello, i past only part of the code
      I´m trying to create a new list depeding  of the choices of the combobox 1,2, and 3, for the combobox 10
      If i ask the choice in the mensage box it respondes correctely, but if i click on the combobox10 it is empty doesnt add the $ps1 (choice of combobox1)
      I get the probleme alredy, is because wen i create the combox10 and the setdata, is before the variable get the value.
      Is there any way to add the combobox inside the loop?
      while 1
      .....
      case $????
      $Combo10 = GUICtrlCreateCombo("Corpo", 273, 53, 75, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
      GUICtrlSetData($combo10, $ps1)
      Any ideas??
      sorry i creat 3 quots and dont know how to erase the 2 empty ones
      Thanks
      #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $dir =("FU\") #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 500, 400, 224, 137) $Button1 = GUICtrlCreateButton("reade var $ps1", 6, 360, 40, 20) GUICtrlSetFont(-1, 8, 400, 0, "Arial") $Pic1 = GUICtrlCreatePic("", 41, 51, 25, 25) $Pic2 = GUICtrlCreatePic("", 41, 83, 25, 25) $Pic3 = GUICtrlCreatePic("", 41, 113, 25, 25) $Combo1 = GUICtrlCreateCombo("Corpo", 73, 53, 75, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) jcorpo($combo1); this funcion will show list of itens $Combo2 = GUICtrlCreateCombo("Corpo", 73, 85, 75, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) jcorpo($combo2) $Combo3 = GUICtrlCreateCombo("Corpo", 73, 115, 75, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) jcorpo($combo3) $Pic10 = GUICtrlCreatePic("", 241, 51, 25, 25) $Combo10 = GUICtrlCreateCombo("Corpo", 273, 53, 75, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData($combo10, $ps1 &"|"& $ps2 &"|"& $ps3); doesnt work, supostely should get the choice of combo1,1 and 3 GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $Button1 MsgBox("0", "test", $ps1, "3") Case $combo1 $ps1 = GUICtrlRead($combo1) img1($combo1, $Pic1, 41, 51); this funcion will show one image depending the choice case $combo2 $ps2 = GUICtrlRead($combo2) if $ps2 = $ps1 Then MsgBox("0", "ERRO", "Repetindo seleção",2) Else img1($combo2, $pic2, 41, 83) EndIf Case $combo3 $ps3 = GUICtrlRead($combo3) if $ps3 = $ps2 or $ps3 = $ps1 Then MsgBox("0", "ERRO", "Repetindo seleção",2) Else img1($combo3, $Pic3, 41, 113) EndIf case $combo10 img1($combo10, $pic10, 41, 145) Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
       
       
       
       
    • galan2015
      My problem with _FileWriteToLine
      By galan2015
      Case $Combo4; Stany $ReadCombo = GUICtrlRead($Combo4) if $ReadCombo = "California" then $ReadFile = FileRead(@ScriptDir&'\Dzielnice\California.txt') GUICtrlSetData($Combo5,$ReadFile) _FileWriteToLine(@ScriptDir&'\cfg\ostatniedane.txt',1,'5') I want overwrite the First line of file ostatniedane.txt but it's only adds another one :/ Anyone Could help me?