littlebigman Posted June 4, 2023 Share Posted June 4, 2023 Hello, I just need to display a listbox, run a for loop that could take minutes and just adds a few items to the list, and then let the user close the application. What would be the right way to do this? It looks like the OnEventMode() would be a better way to keep the GUI responsive. Thank you. ;Opt("GUIOnEventMode", 1) ; Change to OnEvent mode #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 623, 449, 279, 114) $List1 = GUICtrlCreateList("", 8, 8, 601, 422) ;GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton") ;GUICtrlSetOnEvent($iOKButton, "OKButton") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;~ While 1 ;~ Sleep(100) ; Sleep to reduce CPU usage ;~ WEnd ;~ Func CLOSEButton() ;~ ; Note: At this point @GUI_CtrlId would equal $GUI_EVENT_CLOSE, ;~ ; and @GUI_WinHandle would equal $hMainGUI ;~ MsgBox($MB_OK, "GUI Event", "You selected CLOSE! Exiting...") ;~ Exit ;~ EndFunc ;==>CLOSEButton ;~ Exit While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch For $picindx = 1 to UBound($aArray) -1 ;lengthy task Next ;GUICtrlSetData($Form1, "Done.") WinSetTitle($Form1, "Done.", "") ConsoleWrite("Done." & @CRLF) WEnd Link to comment Share on other sites More sharing options...
Andreik Posted June 4, 2023 Share Posted June 4, 2023 For $picindx = 1 to UBound($aArray) -1 Switch GUIGetMsg() ... EndSwitch ; Do your other task Next If an itertation doesn't take too long you can still process GUI messages in that loop so your GUI will remain responsive. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
littlebigman Posted June 5, 2023 Author Share Posted June 5, 2023 Thanks. But then the GUI closes when the code exits the for/next loop, while I need to keep it open to display data I found within the loop. How would I prevent this? For blah $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch ;do stuf Next ;gone! Link to comment Share on other sites More sharing options...
Andreik Posted June 5, 2023 Share Posted June 5, 2023 It doesn't mean you have to exit the program, you could simply ExitLoop. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
littlebigman Posted June 5, 2023 Author Share Posted June 5, 2023 The GUI still closes: For blah $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit ExitLoop EndSwitch ;do stuf Next ;gone! Alternatively, is there some Refresh() command that I could call within the GUI loop to keep the application responsive? Link to comment Share on other sites More sharing options...
argumentum Posted June 5, 2023 Share Posted June 5, 2023 ... you could fork the code. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
littlebigman Posted June 5, 2023 Author Share Posted June 5, 2023 Thanks. What files do I need, and would you have a "Hello, World!" I could try fast and see if it solves the problem? Example_Fork_Broadcast.au3 Example_Fork_BroadcastWithFMIPC.au3 Example_Fork_Events.au3 Example_Fork_FileMonitor.au3 Example_Fork_FileMonitor_NoGui.au3 Example_Fork_Reciever.au3 Example_Fork_TCP.au3 FMIPC.au3 Fork.au3 ForkDbgAid.au3 ForkDbgWr.au3 MailSlot.au3 Link to comment Share on other sites More sharing options...
argumentum Posted June 5, 2023 Share Posted June 5, 2023 (edited) hmm, maybe this is less advanced and gives you a clue : Example() Func Example() Local $sHello = "Hello cru" & "el world" ; ..this way is safer ; discovered after debugging If StringInStr($CmdLineRaw, "/bangbang") Then If WinWait("", $sHello, 5) Then MsgBox(262144, @ScriptName, "Bye cruel world", 1) WinClose("", $sHello) Else MsgBox(262144, @ScriptName, "oops ?", 2) EndIf Else ShellExecute(@AutoItExe, '"' & @ScriptFullPath & '" /bangbang') MsgBox(262144, @ScriptName, $sHello) EndIf EndFunc ..basically you can have a script handle other scripts in whatever creative ways you can apply within your "arsenal of code knowing" / experience Edited June 5, 2023 by argumentum better code Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
littlebigman Posted June 5, 2023 Author Share Posted June 5, 2023 Not sure how I can get control back to the GUI once the code was launched with ShellExecute(). I'll read the examples to fork. Link to comment Share on other sites More sharing options...
Andreik Posted June 5, 2023 Share Posted June 5, 2023 5 hours ago, littlebigman said: The GUI still closes: For blah $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit ExitLoop EndSwitch ;do stuf Next ;gone! Alternatively, is there some Refresh() command that I could call within the GUI loop to keep the application responsive? You're joking. The GUI close if you close it or if the script ends. You must be more specific about what do stuff and lengthy task means. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
littlebigman Posted June 5, 2023 Author Share Posted June 5, 2023 The for/next loop is a task that can take minutes, and will just add some items to the listbox. That's why I need a way to keep the GUI responsive, and keep it open once I'm out of the loop. Link to comment Share on other sites More sharing options...
Solution Andreik Posted June 5, 2023 Solution Share Posted June 5, 2023 (edited) I still don't get what do you mean to keep the GUI responsive. Something like that? $hMain = GUICreate('Whatever', 400, 400) $cListBox = GUICtrlCreateList('', 10, 10, 390, 350) $cButton = GUICtrlCreateButton('Click me', 100, 365, 200, 30) GUISetState(@SW_SHOW, $hMain) While True ProcessMessages() AdlibRegister('ProcessMessages', 30) For $Index = 1 To 1000 ; If a loop doesn't take seconds ; you can remove adlib and process ; messages here ; ProcessMessages() GUICtrlSetData($cListBox, $Index) Sleep(500) Next AdlibUnRegister('ProcessMessages') Sleep(10) WEnd Func ProcessMessages() Switch GUIGetMsg() Case -3 Exit Case $cButton ConsoleWrite('Hi there!!' & @CRLF) EndSwitch EndFunc Edited June 5, 2023 by Andreik littlebigman 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
littlebigman Posted June 6, 2023 Author Share Posted June 6, 2023 (edited) Thank you! #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 623, 449, 279, 114) $List1 = GUICtrlCreateList("", 0, 52, 622, 396) $Label1 = GUICtrlCreateLabel("Label1", 8, 8, 428, 31) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func ProcessGUI() Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch EndFunc For blah ProcessGUI() ;to keep the GUI responsive ;do stuff Next WinSetTitle($Form1, "", "Done!") ;So the app doesn't close after the for loop While True $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Edited June 6, 2023 by littlebigman Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now