Sign in to follow this  
Followers 0
3mustgetbeers

GUI freezes??

11 posts in this topic

Hi Guys!

(Background)

I have a GUI with 3 buttons; 'Yes', 'No' and 'Exempt' to deal with application forms gathered for market research (opting in or out).

The idea is, the user has a PDF application form with a tick box that the applicant has ticked or omitted. If ticked, they are opting out of market research. If not, they opt in. If the for is missing for that account number, for is missing or is a poor (unreadable scan), the applicant is opted out of market research.

The only difference in the buttons is the letter they put on the spreadsheet - 'I' for opting in, 'O' for out and 'X' for exempt.

(The point!)

In & Out work fine; fill in the spreadsheet, copy the next account number, past in to a search field in an archive and bring bring up the next form. Great! I did comething right ;))

Problem is the Exempt button. When clicked, it launches another GUI with 3 reasons why its exempt (radio buttons):

- no application form

- application unreadable (poor scan)

- application partially missing

Now, when one is selected it works, to an extent, in that it closes that second (is it called child??) GUI, fills in the spreadsheet with the X in the relevant cell, puts the explanation in the next cell and opens the next application form. However, the original GUI (with the 3 buttons) no longer works - even the 'red X' in the corner??

Is it looping somewhere? Does the 2nd GUI need to be in a funtion rather than with in the While statement of the original GUI?? I just can't see where I'm going wrong - though from previous posts no doubt you gurus will spot it straight off!!

Appologise for the long winded nature, have a knack for that! Any more info needed let me know,

Cheers

3mustgetbeers

; Creates the GUi & sets window position
$AndysLittleTool = GUICreate("NRPLCv1", 223, 110, 785, 632, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

SetWindowPos($AndysLittleTool, $HWND_TOPMOST + $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE))

Func SetWindowPos($hwnd, $InsertHwnd, $X, $Y, $cX, $cY, $uFlags)
    $ret = DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $hwnd, "hwnd", $InsertHwnd, _
            "int", $X, "int", $Y, "int", $cX, "int", $cY, "long", $uFlags)
    Return $ret[0]
EndFunc

$Title = GUICtrlCreateLabel("Andys Little Tool!", 30, 8, 189, 33)
GUICtrlSetFont(-1, 16, 400, 0, "Arial")
$Copyright = GUICtrlCreateLabel("Designed and Implemented by Andy Lee", 15, 40, 235, 19)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Rights = GUICtrlCreateLabel("All Rights Reserved", 70, 55, 185, 19)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$opt_in = GUICtrlCreateButton("opt In", 17, 80, 51, 25)
$opt_out = GUICtrlCreateButton("opt Out", 80, 80, 59, 25)
$eXempt = GUICtrlCreateButton("eXempt", 150, 80, 51, 25)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $opt_in
            InputYes()

        Case $opt_out
            InputNo()

        Case $eXempt
            $eXMenu = GUICreate("Exepmt Menu", 317, 210, 495, 325)
            GUICtrlSetFont(-1, 16, 400, 0, "Arial")

            $opt1 = GUICtrlCreateRadio("No Application Form", 28, 80, 285, 17)
            GUICtrlSetFont(-1, 13, 400, 0, "Arial")

            $opt2 = GUICtrlCreateRadio("Application Form Unreadable", 28, 112, 285, 17)
            GUICtrlSetFont(-1, 13, 400, 0, "Arial")

            $opt3 = GUICtrlCreateRadio("Application Form Partially Missing", 28, 144, 273, 17)
            GUICtrlSetFont(-1, 13, 400, 0, "Arial")

            GUISetState(@SW_SHOW)

            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($eXMenu)

                    case $opt1
                        GUIDelete($eXMenu)
                        Exempt1()

                    Case $opt2
                        GUIDelete($eXMenu)
                        Exempt2()

                    Case $opt2
                        GUIDelete($eXMenu)
                        Exempt3()

                EndSwitch
            WEnd
    EndSwitch
WEnd

Share this post


Link to post
Share on other sites



3mustgetbeers,

It looks as if you never leave the child While...WEnd loop. Try putting an ExitLoop as the final command in each of the Cases within it - then you exit that loop and return to the main While...WEnd loop again making the main GUI active. ;)

You might also find the Managing Multiple GUIs tutorial in the Wiki of interest. ;)

Let me know if it works. :)

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

Melba23 - you're a hero mate! Works a treat and is pretty obvious now you point it out!

1 small problem - when I click on the exempt button the font changes on the button itself (i.e. goes a lot bigger) Can't see where in the code it would make it do this??

Cheers mate

Share this post


Link to post
Share on other sites

3mustgetbeers,

That one is easy! ;)

Case $eXempt
    $eXMenu = GUICreate("Exepmt Menu", 317, 210, 495, 325)
    GUICtrlSetFont(-1, 16, 400, 0, "Arial") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

In the indicated line the "-1" refers to last control created - which just happens to be $eXempt! :)

Solution: Either use GUISetFont here and then you no longer need the GUICtrlSetFonts for the radios, or just delete that line. ;)

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

Sorry Melba, I mean the text on the button face of the parent GUI -

$eXempt = GUICtrlCreateButton("eXempt", 150, 80, 51, 25)

Looks fine until clicked. When it is clicked the child GUI appears but the text on Exempt button on the parent GUI goes massive! Even when the child is closed it doesn't revert??

Thanks for your time by the way!

Share this post


Link to post
Share on other sites

3mustgetbeers,

If you do not believe me, look at the script: ;)

; Creates the GUi & sets window position
$AndysLittleTool = GUICreate("NRPLCv1", 223, 110, 785, 632, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS), $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)

SetWindowPos($AndysLittleTool, $HWND_TOPMOST + $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_NOMOVE, $SWP_NOSIZE))

Func SetWindowPos($hwnd, $InsertHwnd, $X, $Y, $cX, $cY, $uFlags)
    $ret = DllCall("user32.dll", "long", "SetWindowPos", "hwnd", $hwnd, "hwnd", $InsertHwnd, _
            "int", $X, "int", $Y, "int", $cX, "int", $cY, "long", $uFlags)
    Return $ret[0]
EndFunc

$Title = GUICtrlCreateLabel("Andys Little Tool!", 30, 8, 189, 33)
GUICtrlSetFont(-1, 16, 400, 0, "Arial")
$Copyright = GUICtrlCreateLabel("Designed and Implemented by Andy Lee", 15, 40, 235, 19)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Rights = GUICtrlCreateLabel("All Rights Reserved", 70, 55, 185, 19)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$opt_in = GUICtrlCreateButton("opt In", 17, 80, 51, 25)
$opt_out = GUICtrlCreateButton("opt Out", 80, 80, 59, 25)
$eXempt = GUICtrlCreateButton("eXempt", 150, 80, 51, 25) ; I am the last control created before the -1 below <<<<<<<<<<<<<<<<<<<<<<<<<<<
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $opt_in
            InputYes()

        Case $opt_out
            InputNo()

        Case $eXempt
            $eXMenu = GUICreate("Exepmt Menu", 317, 210, 495, 325)
            GUICtrlSetFont(-1, 16, 400, 0, "Arial") ; -1 references the last control created <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

            $opt1 = GUICtrlCreateRadio("No Application Form", 28, 80, 285, 17)
            GUICtrlSetFont(-1, 13, 400, 0, "Arial")

            $opt2 = GUICtrlCreateRadio("Application Form Unreadable", 28, 112, 285, 17)
            GUICtrlSetFont(-1, 13, 400, 0, "Arial")

            $opt3 = GUICtrlCreateRadio("Application Form Partially Missing", 28, 144, 273, 17)
            GUICtrlSetFont(-1, 13, 400, 0, "Arial")

            GUISetState(@SW_SHOW)

            While 1
                $nMsg = GUIGetMsg()
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($eXMenu)

                    case $opt1
                        GUIDelete($eXMenu)
                        Exempt1()

                    Case $opt2
                        GUIDelete($eXMenu)
                        Exempt2()

                    Case $opt2
                        GUIDelete($eXMenu)
                        Exempt3()

                EndSwitch
            WEnd
    EndSwitch
WEnd

I hate to say "I told you so", but I did! :)

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

Melba, yes you're quite right!

The Font line should not have been there, but used underneath the $Title label, which I thought it was!

Cheers again mate!

Share this post


Link to post
Share on other sites

Hi guys!

I've got a similar problem. My script parses HTML pages and downloads images in a number of nested loops. As the process goes on, the GUI freezes, the mouse cursor turns into the sand clock, and the window blanks out. Here's a piece of code.

The general GUI message processing loop

; create gui
$gui = GUICreate("XuKer!", 500, 200)
$btn_browsedir = GUICtrlCreateButton("...", 470, 20, 20, 20)
$lab_saveto = GUICtrlCreateLabel("Сохранить в:", 10, 3, 100)
GUICtrlSetColor(-1, 0x0000ff)
$edit_savedir = GUICtrlCreateEdit(@DesktopDir, 10, 20, 455, 20, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL))
$lab_pagestart = GUICtrlCreateLabel("Страницы с:", 10, 50, 70)
GUICtrlSetColor(-1, 0xff0000)
$edit_pagestart = GUICtrlCreateEdit("1", 80, 48, 40, 20, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL))
GUICtrlSetBkColor(-1, 0xffff00)
$lab_pageend = GUICtrlCreateLabel("по:", 130, 50, 30)
GUICtrlSetColor(-1, 0xff0000)
$edit_pageend = GUICtrlCreateEdit("1", 155, 48, 40, 20, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL))
GUICtrlSetBkColor(-1, 0xffff00)
$check_getall = GUICtrlCreateCheckbox("Все галереи (долго!)", 210, 48, 120, 20)
GUICtrlSetState(-1, $GUI_UNCHECKED)

$btn_start = GUICtrlCreateButton("Download", 160, 80, 200, 30)
$lab_descproc = GUICtrlCreateLabel("Current:", 10, 115, 120)
GUICtrlSetColor(-1, 0x0000ff)
$lab_proc = GUICtrlCreateLabel("...", 160, 115, 300)
GUICtrlSetColor(-1, 0x000000)
$pr_proc = GUICtrlCreateProgress(10, 130, 480, 20, $PBS_SMOOTH)
GUICtrlSetBkColor(-1, 0)
GUICtrlSetColor(-1, 0x00ff00)
GUICtrlSetData(-1, 0)
GUICtrlSetState(-1, $GUI_SHOW)
$lab_descall = GUICtrlCreateLabel("Total:", 10, 155, 120)
GUICtrlSetColor(-1, 0x0000ff)
$lab_all = GUICtrlCreateLabel("...", 160, 155, 300)
GUICtrlSetColor(-1, 0x000000)
$pr_all = GUICtrlCreateProgress(10, 170, 480, 20, $PBS_SMOOTH)
GUICtrlSetBkColor(-1, 0)
GUICtrlSetColor(-1, 0x00ff00)
GUICtrlSetData(-1, 0)
GUICtrlSetState(-1, $GUI_SHOW)

; Where to save
$savedir = "D:\xuk"
GUICtrlSetData($edit_savedir, $savedir)

GUISetState(@SW_SHOW)

While True

    $msg = GUIGetMsg()

    Select
        Case $msg = $check_getall ; the checkbox has been clicked
            $checked = GUICtrlRead($check_getall)
            If $checked = $GUI_CHECKED Then
                GUICtrlSetData($edit_pagestart, "1")
                GUICtrlSetData($edit_pageend, "580")
            EndIf

        Case $msg = $edit_pagestart ; the edit text has changed
            $txt = GUICtrlRead($edit_pagestart)
            If Int($txt) < 1 Then
                GUICtrlSetData($edit_pagestart, "1")
            ElseIf Int($txt) > Int(GUICtrlRead($edit_pageend)) Then
                GUICtrlSetData($edit_pagestart, GUICtrlRead($edit_pageend))
            EndIf

            If ( Not (Int($txt) = 1) And (Int(GUICtrlRead($edit_pageend)) = 580)) Then
                GUICtrlSetState($check_getall, $GUI_UNCHECKED)
            Else
                GUICtrlSetState($check_getall, $GUI_CHECKED)
            EndIf

        Case $msg = $edit_pageend ; the edit text has changed
            $txt1 = GUICtrlRead($edit_pageend)
            If Int($txt1) < Int(GUICtrlRead($edit_pagestart)) Then
                GUICtrlSetData($edit_pageend, GUICtrlRead($edit_pagestart))
            ElseIf Int($txt1) > 580 Then
                GUICtrlSetData($edit_pageend, "580")
            EndIf

            If ( Not (Int(GUICtrlRead($edit_pagestart)) = 1) And (Int($txt1) = 580)) Then
                GUICtrlSetState($check_getall, $GUI_UNCHECKED)
            Else
                GUICtrlSetState($check_getall, $GUI_CHECKED)
            EndIf

        Case $msg = $btn_browsedir ; the browse button
            ; browse for target directory
            $selecteddir = FileSelectFolder("Выбрать папку для сохранения", "", 2, "", $gui)
            If $selecteddir <> "" And FileExists($selecteddir) Then
                $savedir = $selecteddir
                GUICtrlSetData($edit_savedir, $savedir)
            EndIf

        Case $msg = $btn_start ; the start button is pressed
            ; DOWNLOAD THE IMAGES
            $savedir = GUICtrlRead($edit_savedir)
            GetAll()
            $res = MsgBox(4, "Download complete!", "Open target dir now?")
            If $res = 6 Then
                ShellExecute($savedir, "", "", "open")
            EndIf
            ExitLoop

        Case $msg = $GUI_EVENT_CLOSE ; the window is being closed
            ExitLoop

    EndSelect

WEnd

The main funtion (GetAll) called in the $btn_start event

Func GetAll() ; 

    HttpSetProxy(0)

    ; create putput folders
    ; ...

    For $k = $startpage To $endpage
        ; Dim variables (or reset them)
        ; ...

        ; Save page $k as HTML by InetGet
        ; ...

        ; parse the file
        $start_find = 1
        $pos = StringInStr($file_str, "<td class=""contentheading1"">", 0, 1, $start_find)
        While $pos > 0
            ; ...here the text is parsed and the data written into an array
        WEnd

        
        ; скачивание и разбор файлов девушек

        For $i = 0 To $count - 1 ; loop through the number of element in array

            ; download page $i by InetGet
            ; ...

            ; parse the file            
            $pos = StringInStr($file_str1, "http://img", 0, 1, $start_find)
            $pos1 = StringInStr($file_str1, """", 0, 1, $pos)
            While ($pos > 0) And ($pos1 > $pos) And ($n < $a_girls[$i][3] - 1)
                ; ...here the text is parsed and the data written into the array
            WEnd

            
            For $n = 0 To UBound($a_pics) - 1
                ; download image $n using InetGet
                ; ...

                _WinAPI_RedrawWindow($gui) ; GUI antifreeze?
            Next
            
            ;;;
            ; update progress bars etc

            _WinAPI_RedrawWindow($gui) ; GUI antifreeze?
        Next

    Next

EndFunc   ;==>GetAll

If it were Borland C++ Builder, I'd use the expression Application->ProcessMessages(); at the end of each loop so that the window doesn't freeze (this helps 100%!) But here I think there must be some other ways of dealing with that. Say, is it possible to write a function that queries all the components on the main form for any messages? I've tried to use WinAPI redraw (as seen in the example), but that didn't work with me.

Any ideas?

Share this post


Link to post
Share on other sites

S0mbre,

I do not believe your problem is at all similar to OP's case. Rather then hijack threads, please just start a new one next time. :D

Now, there is no reason that I can see why your code should produce the symptoms that you observe. First, understand that as Autoit is not multi-threaded nothing will happen within the main GUI loop until you return from a function - so your controls are lifeless until your GetAll function returns, unless you do something about it as discussed in the Interrupting a running function tutorial in the Wiki. :graduated:

So I think you are getting stuck somewhere in the GetAll function - probably one of the While...WEnd loops. I suggest adding this to the top of your script:

Opt("TrayIconDebug", 1)

Now you will get the currently executing line shown in a tooltip when you hover the mouse over the tray icon. I will be surprised if you do not end up in an endless loop somewhere within your function. Let me know how you get on. :(

By the way, rather than use Edit controls for the data input to your GUI, I would recommend using Inputs - they are designed for that type of work and do not need the styles added. :D

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

Hi! Thanks for advice. Actually, my script did run okay with no changes after my Internet connection got better. So I don't think I'll improve on the code any further. Thank you!

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
Sign in to follow this  
Followers 0