GUI Exit Problem

  • Hallo liebe Forum member,

    ich habe hier folgendes problem:
    ich habe ein programm geschrieben, das eine GUI
    hat und einen loop durchläuft, um zu prüfen, ob ein
    anderes programm läuft.
    wenn das nicht der fall ist, soll dieses programm gestartet werden
    es sieht volgendermaßen aus:

    [autoit]


    #include <GUIConstants.au3>
    AutoItSetOption("WinTitleMatchMode", 2)
    GUICreate ( "programm" , 300 , 450)
    $create = GUICtrlCreateButton("Create", 125, 265, 60)
    GUICtrlCreateLabel( "Crashes:" , 100 , 100)
    $i = 0
    $number = GUICtrlCreateLabel( $i , 150 , 100)
    GUISetState (@SW_SHOW)

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

    While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    if not WinExists("titel") or WinExists("teiltitel") then
    if FileExists("programm.exe") Then
    run("programm.exe")
    EndIf
    $i = $i + 1
    GUICtrlDelete($number)
    $number = GUICtrlCreateLabel( $i , 150 , 100)
    $msg=GUIGetMsg()
    sleep (1000)
    $msg=GUIGetMsg()
    EndIf
    Wend

    [/autoit]

    das problem:
    ich kann das programm nur noch übers tray icon schließen =(
    gibts da ne abhilfe?


    Grüße TheJoker89

    • Offizieller Beitrag

    Probier mal so:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    AutoItSetOption("WinTitleMatchMode", 2)
    GUICreate ( "programm" , 300 , 450)
    $create = GUICtrlCreateButton("Create", 125, 265, 60)
    GUICtrlCreateLabel( "Crashes:" , 100 , 100)
    $i = 0
    $number = GUICtrlCreateLabel( $i , 150 , 100)
    GUISetState (@SW_SHOW)

    While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    if not WinExists("titel") or WinExists("teiltitel") then
    if FileExists("programm.exe") Then run("programm.exe")
    $i = $i + 1
    GUICtrlSetData($number, $i)
    EndIf
    Wend

    [/autoit]

    Edit:
    Ist das gewollt:

    [autoit]

    if not WinExists("titel") or WinExists("teiltitel") then

    [/autoit]


    = Wenn "titel" nicht existiert ODER "teiltitel" existiert dann

  • danke für deinen ansatz, habe bereits herrausgefunden,
    dass das problem die sleep funktion ist, die ich aber brauche!!
    der rechner würde sonst unnötig viel belastet...

    EDIT: btw das guictrlsetdata war eigentlich unnötig oder? ;)

    EDIT2: ach sehe gerade, du hast das ganze nur noch abstrahiert ^^
    war somit doch nicht unnötig :D

    2 Mal editiert, zuletzt von TheJoker89 (6. Juni 2007 um 22:53)

    • Offizieller Beitrag
    Zitat

    dass das problem die sleep funktion ist, die ich aber brauche!!
    der rechner würde sonst unnötig viel belastet...


    Wenn du mit "GUIGetMsg()" arbeitest, brauchst du das Sleep nicht. Wenn du es verwendest reicht ein Sleep(100), CPU-Last dann bei 8 - 12 %.

  • gibts da noch ne andere methode (außer hotkeys)
    um das programm zu schließen?
    und btw. ich möchts möglichst unter 2% halten ;)

    gehe jetzt erstmal schlafen, bis morgen :D

    Einmal editiert, zuletzt von TheJoker89 (6. Juni 2007 um 22:59)

    • Offizieller Beitrag

    HI,

    oder so:

    Spoiler anzeigen
    [autoit]

    Opt("WinTitleMatchMode", 2)

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

    HotKeySet("^5", '_end')
    HotKeySet("^2", '_show')

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

    Global $status = True, $i = 0

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

    While 1
    If Not WinExists("Internet Explorer") Or WinExists("teiltitel") Then
    If FileExists("programm.exe") Then Run("programm.exe")
    $i += 1
    EndIf
    Sleep(1000)
    WEnd

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

    Func _show()
    If $status Then
    ConsoleWrite($i & @CRLF)
    ToolTip('Crashes : ' & $i, 0, 0)
    Else
    ToolTip('')
    EndIf
    $status = Not $status
    EndFunc ;==>_show

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

    Func _end()
    Exit (0)
    EndFunc ;==>_end

    [/autoit]

    So long,

    Mega

  • gibts nicht irgendwas ohne hotkeys?
    autoit ist doch ne sprache in der guis möglich sind,
    deswegen muss es doch auch möglich sein diese
    während einer do schleife zu beenden oder?

  • wie wärs mit nem simplen aufs 'X' drücken?
    das sollte doch auch gehen oder?