Jump to content

Loop Function with GUI


DTools
 Share

Recommended Posts

Hi All,

This is my first time writing here, and I hope to get some assistant with an issue I'm facing.

I created a GUI window with a button that calls a function in a Loop.

The problem is that I cannot click on anything during the running function even not to close the GUI window.

I'm trying to understand if there is any way to run this function in a loop and still be able to close the windows with the X even though the function is still running.

I understand that I can use the "HotKeySet" but it's not what I'm searching for.

I'm adding a code example of what I'm trying to do that will simulate the process and the problem, in this case I cannot close the window, only from the tray.

Thanks in advance!

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

Global $FileInput, $listview, $GenButton, $FileInputRead, $Line1, $Line2, $Line3
Call("ListUpdate")
Func ListUpdate()
    GUICreate("",300,300,Default)
    $listview = GUICtrlCreateListView("Test",Default,Default,300,200,$LVS_NOSORTHEADER)
    $Line1 = "Line1"
    $Line2 = "Line2"
    $Line3 = "Line3"
    $GenButton = GUICtrlCreateButton("Show Lines",5,200,200)
    GUISetState()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GenButton
            _GenList()
    EndSwitch
WEnd
EndFunc
Func _GenList()
        _GUICtrlListView_DeleteAllItems($listview)
        $SetLine = GUICtrlCreateListViewItem($Line1,$listview)
        $SetLine = GUICtrlCreateListViewItem($Line2,$listview)
        $SetLine = GUICtrlCreateListViewItem($Line3,$listview)
        Sleep(5000)
        Call("_GenList")
EndFunc
Link to comment
Share on other sites

Thanks for the answer  jaberwocky6669,

I know it's because call(_GenList), i need this loop.

The main idea is to refresh and update this list based on dynamic variables that will change.

But still I want to be able to close this window with the X, or creating more buttons and function that will work in parallel.

Link to comment
Share on other sites

  • Moderators

DTools,

 

if there is any way to run this function in a loop and still be able to close the windows with the X even though the function is still running

Returning to the initial request, you can do it like this:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <MenuConstants.au3>

Global $fInterrupt = False

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Run Func", 10, 10, 80, 30)

GUISetState()

GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            _Run_Func()
    EndSwitch
WEnd

Func _Run_Func()
    ConsoleWrite("Entering infinite loop" & @CRLF)
    While 1
        Sleep(10)
        If $fInterrupt Then
            ConsoleWrite("Interrupting function" & @CRLF)
            Exit
        EndIf
    WEnd
EndFunc

Func _WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case $SC_CLOSE
            ConsoleWrite("[X] clicked" & @CRLF)
            $fInterrupt = True
    EndSwitch
EndFunc
You might also like to look at the Interrupting a running function tutorial in the Wiki. :)

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

Hi, I Already work with this procedure and it didn't helped in my case, the window was still stuck.

Anyway I found a solution to this issue. (Some workaround)

I Added another combo menu (GUICtrlCreateCombo) to the GUI that can be changed during the running function,
And also few lines in the looping function to check the value in this menu, and stop the loop if needed.

Also I added the HotKeySet to configure "ESC" to exit when the function is running if needed.

Thanks for you help!

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