Jump to content

Why is this GUI crashing?


zielke
 Share

Recommended Posts

I've just created this GUI but when I add the while-loop, it crashes....why? Whithout the while-loop it works fine.

GUISetState(@SW_DISABLE,$mGUI)
        $profs = _FileListToArray(ppath(),"*")
        GUICreate ( "Select profile to backup:",300,96,-1,-1,$WS_BORDER,$WS_EX_STATICEDGE)
        $dat2= _ArrayToString($profs,"|",3); split Array to write profile-array into combo-box
        $dropdown = GUICtrlCreateCombo($profs[2], 55, 8)
        GUICtrlSetData(-1,$dat2); fill the combo box
        $button1 = GUICtrlCreateButton("OK",110,45,70,24)
        GUICtrlCreateLabel ( "Profiles:", 8, 10)
        GUISetState()
        While 1
            $msg = GUIGetMsg()
            Select
                Case $msg = $button1
                    Return _GUICtrlComboBox_GetCurSel ($dropdown)
                    GUISetState(@SW_SHOW,$mGUI)
                    ExitLoop
            EndSelect
        WEnd
Edited by zielke
Link to comment
Share on other sites

have

while 1
   $msg = guigetmsg()
    if $msg = $GUI_EVENT_CLOSE then exit
   ;what ever esle you want
wend

NOT TESTED should work though

Link to comment
Share on other sites

@zielke,

You haven't provided enough of your script to replicate the problem.

Based on what you have though, it looks like you have an existing GUI, $mGUI, which you disable and then create a new GUI?

To interact with/poll the new GUI, you need a GuiSwitch() statement.

Link to comment
Share on other sites

Dang! Thought it was the only thing I forgot but it's still crashing (hangs up).

Here's the full function, and yes, there is a second (main gui):

Func listprofiles()
    Local $profs, $profgui, $dat2, $dropdown, $button1, $selgui, $msg
    If ppath() = "False" Then
        Return "False"
    Else
        GUISetState(@SW_DISABLE,$mGUI)
        $profs = _FileListToArray(ppath(),"*")
        $selgui = GUICreate ( "Select profile to backup:",300,96,-1,-1,$WS_BORDER,$WS_EX_STATICEDGE)
        $dat2= _ArrayToString($profs,"|",3); split Array to write profile-array into combo-box
        $dropdown = GUICtrlCreateCombo($profs[2], 55, 8)
        GUICtrlSetData(-1,$dat2); fill the combo box
        $button1 = GUICtrlCreateButton("OK",110,45,70,24)
        GUICtrlCreateLabel ( "Profiles:", 8, 10)
        GUISwitch ($selgui)
        GUISetState()
        While 1
           $msg = guigetmsg()
            If $msg = $GUI_EVENT_CLOSE then ExitLoop
            If $msg = $button1 Then 
                        Return _GUICtrlComboBox_GetCurSel ($dropdown)
                        ExitLoop
                        EndIf
        WEnd
        GUISwitch ($mGUI)
        GUIDelete ($selgui)
    EndIf
EndFunc

Any solutions?

Edited by zielke
Link to comment
Share on other sites

Dang! Thought it was the only thing I forgot but it's still crashing (hangs up).

Here's the full function, and yes, there is a second (main gui):

;code removed

Any solutions?

We have to guess since you don't like to provide all the script.

Maybe it's because you are returning without deleting the new gui and switching back to the old one, so this could fix it.

;code removed

EDIT: Moved the "Return $Result" line inside the function.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

OK, heres the full code:

;code removed

You need to correct the errors before the script will run and then can you tell me if the modified function I suggested cures the problem? But I see that I reversed the last two lines in my post so I'll correct that.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Tried your solution using the $Result var but still the same crashing problem... CPU load stays normal.

What needs to be done to see the problem? Are any files needed to run the script and see the problem. What do you mean by 'crash'?

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

When triggering the listprofiles()-function the new GUI partitially pops up (only shows the combo-box, but no OK-button) and then it freezes (process-doesn't-respond-message from Windows comes up).

The main problem is the use of your WM_COMMAND function. Functions like that which are called by windows messages need to be executed and finished as soon as possible because that message will be fired again for all sorts of reasons. If you call another function, like listprofiles, which creates a gui and waits for a response then wm_command will be calling that function repeatedly while you are still executing it.

So I have modified your code a bit to show a way to deal with this, but only for the option you said you had a problem with, though you can easily repeat the process for the other cases.

You also need to be able to distinguish between guis IMO so that you know which one a message is from so I made a change related to that.

I also commented out some of the lines in listprofiles so I could test it.

;code removed
Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

OK I managed to use another way instead of WMCommand:

Func _MainGUI()
    Local $msg, $filemenu, $restoreitem, $backupitem, $quititem, $helpmenu, $upditem, $infoitem, $selprof


; Create GUI
    $mGUI = GUICreate($versionstring, 372, 148)
    GUICtrlCreatePic ( @TempDir & "\splash.bmp",0,0,373,128)

; file menu
    $filemenu = GUICtrlCreateMenu("&File")
    $restoreitem = GUICtrlCreateMenuItem("Restore", $filemenu)
    $backupitem = GUICtrlCreateMenuItem("Backup", $filemenu)
    $quititem = GUICtrlCreateMenuItem("Quit", $filemenu)
    $helpmenu = GUICtrlCreateMenu("?")
    $upditem = GUICtrlCreateMenuItem("Check for Updates", $helpmenu)
    $infoitem = GUICtrlCreateMenuItem("About", $helpmenu)
    GUISetState()
    
; Loop until user exits
    While 1
        $msg = GUIGetMsg()
            If $msg = $GUI_EVENT_CLOSE Then
                Exit
            EndIf
            If $msg = $quititem Then
                Exit
            EndIf
            If $msg = $restoreitem Then
                restoreprofile()
            EndIf
            If $msg = $backupitem Then
                $selprof = listprofiles()
                saveprofile($selprof)
            EndIf
            If $msg = $upditem Then
                MsgBox (0, "Info", ppath())
            EndIf
            If $msg = $infoitem Then
                MsgBox (0, "Info", $versionstring & Chr(13) & Chr(13)& "by *fReSh*jzaboo <jzaboo at gmail dot com>." & Chr(13) & "Feel free to send bug reports or suggestions for this tool.",0,$mGUI)
            EndIf
    WEnd
EndFunc  ;==>_MainGUI
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...