Jump to content

How to update autoit listbox from a subscript?


Go to solution Solved by Zedna,

Recommended Posts

I have a listbox in my gui that serves as a log. 

Global $listBoxStyle = BitOr($LBS_NOTIFY, $WS_VSCROLL, $WS_BORDER)
Global $lstLog = GUICtrlCreateList("", 30, 155, 346, 176, $listBoxStyle)

The main code updates it just fine with

GUICtrlSetData($lstLog,_NowTime(5) & " " & $msg)

I have subscripts that run using Run('...... var1 var2 ...)

I would like those other scripts to update my log window as well. How?

I have tried the same GUICtrlSetData line however it doesn't work. Both using the $lstlog passed to the script and using "$lstLog = ControlGetHandle("Automation","","[CLASS:ListBox; INSTANCE:1]").

I have also tried _GUICtrlListBox_AddString and one other version of the same I think.

Link to comment
Share on other sites

Link to comment
Share on other sites

Both    

         $lstLog = ControlGetHandle("Applanix Automation","","[CLASS:ListBox; INSTANCE:1]")
            ConsoleWrite("Win exists: " & $lstLog & @CRLF)
            $lstLog = ControlGetHandle("Applanix Automation","","ListBox1")
            ConsoleWrite("Win exists: " & $lstLog & @CRLF)

Returns 
Win exists: 0x00700642
Win exists: 0x00700642

Link to comment
Share on other sites

Ok, well that is a good sign.  The handle does seems a little short to me (thinking x86 versus x64).  Are the subscripts  and the GUI script all using the same architecture x86/x64?

I'm pretty sure you will need to use the _GUICtrlListBox functions, as using GUICtrlSetData uses the control ID instead of the handle...but you mentioned you already tried that.  What return value do you get from the _GUICtrlListBox_AddString function?

Link to comment
Share on other sites

Sending data to AutoIt window by title or using onboard UDFs is the best solution.

However, reading process text stream is also an option.
Hope my solution helps someone☺
See attachment.

exmpl.au3

Link to comment
Share on other sites

I will look at your example as well @LKP

Apologies in advance if this is already included in the example but similar to my original question, how to I scroll down on the listbox from a subscript? The below doesn't work, presumably for the same problem.

GUICtrlSendMsg("ListBox1", $WM_VSCROLL, $SB_LINEDOWN, 0)

The list in the help file for the ControlCommand doesn't seem to have an obvious parallel to the SendMsg. 

Link to comment
Share on other sites

@LKP Interesting example and I will give it a try since I was needing to separate out GUI from main script anyways since the main script is designed to keep running which means the button controls like closing the gui don't respond until main is 100% done. 

Also, in case it helps anyone else, I put together a tiny function to stop all scripts running using AutoIt3.exe. Could be supplemented to accept array for exes run by automation to kill them too. Seems necessary because Exit only stops that script as best I can tell, not subscripts or sub-subscripts. 

#include <Array.au3>

Func _KillAU3s()
    Global $ProcList
    
    $ProcList = ProcessList()
;~     _ArrayDisplay($ProcList)
    ;Loop through process list and close anything using AutoIt3.exe
    For $x = 1 to $ProcList[0][0]
        If $ProcList[$x][0] = "AutoIt3.exe" Then ProcessClose($ProcList[$x][1])
    Next
EndFunc

I plan on having the GUI part be compiled into an exe so this will work for me. If the main is being run from au3 file as well, will need to figure out how to get PID for the script running this function to exclude it.

Edited by BryanWall
Link to comment
Share on other sites

@BryanWall, I was actualy thinking of making an example that works both for @compiled and not, but everything I could google works only for compiled scripts.
The sipmle solution (ignoring UDFs) is to create temporary files somewhere in @AppDataCommonDir or elsewhere and cleanup when subscripts exit, but it is kinda boring.

Couldnt find $AutoHScroll style in help files, but you can just select an element every time you add one.

Func _Hndl_Stream()
    Local $sData
    For $i = 1 to UBound($aChildPIDs) - 1
        If ProcessExists($aChildPIDs[$i]) Then
            $sData = StdoutRead($aChildPIDs[$i])
            If $sData <> '' Then 
                GUICtrlSetData($idLog, $sData)
                ControlCommand($hGui, '', $idLog, 'SelectString', $sData)
            EndIf
        EndIf
    Next
EndFunc

P.s.
Dont know what you are doing but HelpFile & Local MVPs recomend compiling everyting ¯\_(ツ)_/¯

Edited by LKP
Link to comment
Share on other sites

  • 2 weeks later...

@LKP Interesting. I'll look into it.

That said, I have a side question. Do you know how to add a horizontal scroll the listbox?

I have tried $WS_HSCROLL, and I have tried using _GUICtrlListView_SetColumnWidth to set the listbox column width to be larger than the listbox itself as one post suggested.

None of it is working.

#Include <SQLite.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <Date.au3>
#include <File.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScrollBarConstants.au3>
#Include <Math.au3>
#Include <Inet.au3>

#Region CreateGUI
    ;create gui
    Global $hGUI = GUICreate("Applanix Automation", 400, 350, 210, 0)
    GUISetOnEvent($GUI_EVENT_CLOSE, EndCode)

    Global $btnBrowse = GUICtrlCreateButton("Start", 10, 2, 76, 20)
    Global $lblBrowse = GUICtrlCreateLabel("Project Directory", 100, 5, 286, 16)
    Global $Label_5 = GUICtrlCreateLabel("APPLANIX", 10, 30, 76, 20)
    Global $Label_1 = GUICtrlCreateLabel("TIME SYNC", 10, 55, 76, 20)
    Global $Label_2 = GUICtrlCreateLabel("INJ TC", 10, 80, 76, 20)
    Global $Label_3 = GUICtrlCreateLabel("INJ PP", 10, 105, 76, 20)
    Global $Label_4 = GUICtrlCreateLabel("DR", 10, 130, 76, 20)
    Global $lblApplxStatus = GUICtrlCreateLabel("n/x", 100, 30, 56, 20)
    Global $lblTSStatus = GUICtrlCreateLabel("n/x", 100, 55, 56, 20)
    Global $lblITCStatus = GUICtrlCreateLabel("n/x", 100, 80, 56, 20)
    Global $lblIPPStatus = GUICtrlCreateLabel("n/x", 100, 105, 56, 20)
    Global $lblDRStatus = GUICtrlCreateLabel("n/x", 100, 130, 56, 20)
    Global $lstLog = GUICtrlCreateList(" ", 30, 155, 346, 176, $listBoxStyle)
    GUISetState(@SW_SHOWNORMAL)

    for $i = 0 to 50
        GUICtrlSetData($lstLog,_NowTime(5) & " " &  50 - $i & " testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt")
    Next

    _GUICtrlListView_SetColumnWidth($lstLog,0,500)
#EndRegion ;CreateGUI


While 1

wend

image.png.57cb6bb7f61592f75ca5a88516da9de2.png

Link to comment
Share on other sites

1) Sorry, it was further up in code, didn't catch that I didn't copy it.


 

Global $listBoxStyle = BitOr($LBS_NOTIFY, $WS_VSCROLL, $WS_HSCROLL)
;~ Global $listBoxStyle = BitOr($LBS_NOTIFY, $WS_VSCROLL, $WS_HSCROLL, $WS_BORDER)

Also, I ended up posting a seperate topic since it is a separate issue and GUIctrlSetLimit is what worked for me.

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