Problem mit GUICreate

  • Hallo,
    ich habe ein Script mit einer Gui, wo ich über Buttons zwei Tasks auswählen kann. Bei dem Task "Check logs" habe ich mitunter eine Function "check_all()", wenn ich das Script starte, erscheint die Gui, wenn ich den ersten Task auswähle, der Task wird ausgeführt (hier habe ich selbst 2 grafische Buttons in jeweils einet Function "OK" und "not_ok" ertsellt.), aber die Gui wird nicht anschließend wieder aufgebaut und das Script hat den Status "paused" unten rechts in der Tasksleiste von XP. Aber wenn ich die Zeile "check_all()" auskommentiere, wird die Gui nach Ausführung des Tasks aufgebaut. Irgend etwas stört den Gui-Aufbau in der Function "check_all()". Ich habe anstelle von "GuiDelete" mit den Optionen GuiSetState(@SW_HIDE / @SW_SHOW) und den anderen Optionen von GuiSetState ausprobiert, leider alles ohne Erfolg. Ich würde mich sehr freuen, wenn jemand eine Lösung für mein Problem hätte.

    Vielen Dank im Voraus.

  • Moin ivan,

    Schleifenproblem !
    Das Script pausiert nicht, sondern bleibt in einer endlosschleife. ;)
    "Wenn Button gedrückt, dann Funktion verlassen"

    Spoiler anzeigen
    [autoit]

    Func OK()
    $handle5 = GUICreate("TEST GUI",1024,768,0,0, $WS_POPUP)
    GUISetBkColor (0x00E0FFFF)
    GUISetFont(18, 400, -1)
    GUICtrlCreateLabel("Tests completed without any failure.", 210, 150, 600, 100, 0x01)
    GUICtrlCreateLabel("(Click the button below to continue)", 260, 185, 500, 100, 0x01)
    $buttonOK = GuiCtrlCreateButton("", 375, 250, 270, 270,$BS_BITMAP)
    GUICtrlSetImage (-1, "C:\Programs\OK.bmp")
    GUISetState () ; will display a dialog box
    While 1 ; will do an endless loop.
    $msg = GUIGetMsg()
    If $msg = $buttonOK Then
    GUIDelete($handle5)
    Return 0 ; will exit the Function !!!
    Sleep(100)
    EndIf
    WEnd
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func not_ok()
    $handle6 = GUICreate("TEST GUI",1024,768,0,0, $WS_POPUP)
    GUISetBkColor (0x00E0FFFF)
    GUISetFont(18, 400, -1)
    GUICtrlCreateLabel("Tests completed with failure!", 210, 130, 600, 100, 0x01)
    GUICtrlCreateLabel("(Click the button below to continue.)", 260, 200, 500, 100, 0x01)
    $button_not_ok = GuiCtrlCreateButton("", 375, 250, 270, 270,$BS_BITMAP)
    GUICtrlSetImage (-1, "C:\Programs\not-ok.bmp")
    GUISetState ()
    While 1 ; will do an endless loop.
    $msg = GUIGetMsg()
    If $msg = $button_not_ok Then
    GuiDelete($handle6)
    Return 0 ; will exit the Function !!!
    Sleep(100)
    EndIf
    WEnd
    EndFunc

    [/autoit]


    Außerdem solltest Du die Vaiablen in Funktionen lokal setzen, außer denen die wirklich global benötigt werden !


    Gruß
    Greenhorn

    EDIT: Oscar war schneller ... ;)
    EDIT #2: Habe dein Script mal ein wenig verstümmelt ... :D
    So ungefähr würde ich da herangehen.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <File.au3>
    #Include <process.au3>

    [/autoit] [autoit][/autoit] [autoit]

    ;Global $USBOK
    ;Global $NOSPACE

    [/autoit] [autoit][/autoit] [autoit]

    $hWndMain = GUICreate("MY GUI",1024,768,-1,-1, $WS_POPUP) ; will create a dialog box that when displayed is centered
    $btnCheckLogs = GUICtrlCreateButton ("Check logs", 422, 200, 180, 100)
    $btnSaveData = GUICtrlCreateButton ( "Save Data", 422, 350, 180, 100)
    GUISetState () ; will display a dialog box

    [/autoit] [autoit][/autoit] [autoit]

    ; MAIN PROGRAM
    While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $btnCheckLogs
    GUISetState(@SW_DISABLE, $hWndMain)
    GUISetState(@SW_HIDE, $hWndMain)
    ;$USBDRIVE = Assign_USB()
    $USBDRIVE = DriveGetDrive('REMOVABLE')
    If @error = 1 Then
    MsgBox(4096,"WARNING", "NO USB MEMORY FOUND!")
    Exit
    Else
    $NOSPACE = Check_USB_Space($USBDRIVE)
    Sleep(100)
    check_all()
    EndIf
    GUISetState(@SW_ENABLE, $hWndMain)
    GUISetState(@SW_SHOW, $hWndMain)
    Case $btnSaveData ; DELETE SYSDATA
    $USBDRIVE = Assign_USB()
    Save_Data()
    MsgBox(0,"INFO", "Data saved")
    EndSwitch
    Wend

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func Assign_USB()

    Local $sDrive
    Local $RemovableDrives = DriveGetDrive('REMOVABLE')
    If @error Then
    Return SetError(1, 0, 0)
    Else
    If $RemovableDrives[0] > 1 Then
    For $i = 1 To $RemovableDrives[0]
    $sDrive = $RemovableDrives[$i]
    ; Was tun wenn mehrere USB Sticks angeschlossen sind ???
    Next
    Else
    Return $RemovableDrives[1]
    EndIf
    EndIf

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Check_USB_Space($drive)

    Local $USBFREESPACE = Round(DriveSpaceFree($drive)) ; calculate free space on USB memory
    ; determine the space of C:\Data
    Local $USERDATASPACE = Round(DirGetSize("C:\Data") / 1024 / 1024) ; calculate space of C:\Data
    If $USBFREESPACE < $USERDATASPACE Then ; Check whether USBmemory has enough space, if not
    $DIFF = ($USERDATASPACE - $USBFREESPACE) ; calculate needed space
    MsgBox(0, "WARNING", "USB memory does NOT have enough space for saving Userdata!" & @CR & "Please use a higher capacity USB memory or make additional " & $DIFF & " MB free space on it")
    MsgBox(0, "SPACE INFO", "The size of directory C:\Data is " & $USERDATASPACE & " MB. " & @CR & "Missing space on USB memory is: " & $DIFF & " MB.")
    Return SetError(1, 0, 0) ; Not enough spae on USB memory
    Else
    Return 0 ; enough space on USB memory
    EndIf

    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func Save_Data()
    Assign_USB()
    If FileExists($USBDRIVE & "\SYSBACKUP") = 0 then
    DirCreate($USBDRIVE & "\SYSBACKUP")
    EndIf
    FileCopy("C:\Data" , $USBDRIVE & "\SYSBACKUP",1)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func OK()
    $hWndOK = GUICreate("OK",1024,768,-1,-1, $WS_POPUP)
    GUISetBkColor (0x00E0FFFF)
    GUISetFont(18, 400, -1)
    GUICtrlCreateLabel("Tests completed without any failure.", 210, 150, 600, 100, 0x01)
    GUICtrlCreateLabel("(Click the button below to continue)", 260, 185, 500, 100, 0x01)
    $btnOK = GuiCtrlCreateButton("", 375, 250, 270, 270,$BS_BITMAP)
    GUICtrlSetImage (-1, "C:\Programs\OK.bmp")
    GUISetState () ; will display a dialog box
    While 1 ; will do an endless loop.
    $msg = GUIGetMsg()
    If $msg = $btnOK Then
    GUIDelete($hWndOK)
    Return 0 ; will exit the Function !!!
    Sleep(100)
    EndIf
    WEnd
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func not_ok()
    $hWndNotOK = GUICreate("NotOK",1024,768,-1,-1, $WS_POPUP)
    GUISetBkColor (0x00E0FFFF)
    GUISetFont(18, 400, -1)
    GUICtrlCreateLabel("Tests completed with failure!", 210, 130, 600, 100, 0x01)
    GUICtrlCreateLabel("(Click the button below to continue.)", 260, 200, 500, 100, 0x01)
    $btnNotOK = GuiCtrlCreateButton("", 375, 250, 270, 270,$BS_BITMAP)
    GUICtrlSetImage (-1, "C:\Programs\not-ok.bmp")
    GUISetState ()
    While 1 ; will do an endless loop.
    $msg = GUIGetMsg()
    If $msg = $btnNotOK Then
    GuiDelete($hWndNotOK)
    Return 0 ; will exit the Function !!!
    Sleep(100)
    EndIf
    WEnd
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func check_all()
    If $NOSPACE = 0 Then
    OK()
    Else
    not_ok()
    EndIf
    EndFunc

    [/autoit]


    Einmal editiert, zuletzt von Greenhorn (12. Februar 2008 um 23:16)

  • Vielen Dank an Oscar und Greenhorn,

    mit der Zeile " Return 0" in den beiden Functions ist das Problem gelöst. Da ich die Gui gelöscht hatte, habe ich mich nicht um die Schleife gekümmert. Nun funktioniert alles wunderbar.

    Greenhorn, vielen Dank für die Tipps und die Optimierung des Scripts.

    Viele Grüße
    Ivan
    :)