Schleife auf Knopfdruck verlassen?

  • Hallo Leute , ich habe mal wieder ein Problem.
    Dazu habe ich wieder ein Beispielscript erstellt, welches mein Problem schildern soll.

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $WMP , $Button2 , $channel = "http://blackbeats.fm/listen.asx" , $Label

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

    $Form1 = GUICreate("Loop-Stop", 247, 109, 426, 173)
    GUISetOnEvent(-3, "_Exit")
    $WMP = ObjCreate("WMPlayer.OCX")
    $Button1 = GUICtrlCreateButton("Play", 24, 56, 81, 41, 0)
    GUICtrlSetOnEvent(-1,"_play")
    $Button2 = GUICtrlCreateButton("Stop", 128, 56, 81, 41, 0)
    GUICtrlSetOnEvent(-1,"_stop")
    $Label = GUICtrlCreateLabel("Label", 32, 16, 80, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)

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

    While Sleep(50)
    WEnd

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

    Func _Exit()
    Exit
    EndFunc

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

    Func _play()
    $WMP.URL = $channel
    $WMP.controls.play()
    GUICtrlSetData($Label,"Loading...")
    While $WMP.playstate <> 3
    ;Falls stop geklickt , soll _stop() aufgerufen werden
    Sleep(20)
    WEnd
    GUICtrlSetData($Label,"Playing")
    EndFunc

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

    Func _stop()
    $WMP.controls.stop()
    GUICtrlSetData($Label,"Stopped")
    EndFunc

    [/autoit]

    Wie kann ich eine Schleife nach einem Klick auf einen Button sofort verlassen ? Wie würdet ihr das machen?
    Am besten ohne GuiGetMsg() , wenn , dann mit GuiGetCursorInfo().

    MfG hellboy

    [autoit]

    Do
    _help($user)
    Until $questions = 0

    [/autoit]

    Meine Werke:
    Ste`s Web-Radio

    Einmal editiert, zuletzt von hellboy3 (22. Januar 2011 um 12:41)

  • Wenn es unbeddingt der Stop-Button sein muss, kannst du es so machen:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $WMP , $Button2 , $channel = "http://blackbeats.fm/listen.asx" , $Label

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

    $Form1 = GUICreate("Loop-Stop", 247, 109, 426, 173)
    GUISetOnEvent(-3, "_Exit")
    $WMP = ObjCreate("WMPlayer.OCX")
    $Button1 = GUICtrlCreateButton("Play", 24, 56, 81, 41, 0)
    GUICtrlSetOnEvent(-1,"_play")
    $Button2 = GUICtrlCreateButton("Stop", 128, 56, 81, 41, 0)
    GUICtrlSetOnEvent(-1,"_stop")
    $Label = GUICtrlCreateLabel("Label", 32, 16, 80, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)

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

    While Sleep(50)
    WEnd

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

    Func _Exit()
    Exit
    EndFunc

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

    Func _play()
    $WMP.URL = $channel
    $WMP.controls.play()
    GUICtrlSetData($Label,"Loading...")
    $oldOneEvent = Opt("GUIOnEventMode", 0)
    While $WMP.playstate <> 3
    ;Falls stop geklickt , soll _stop() aufgerufen werden
    if GUIGetMsg($Button2) Then ExitLoop
    Sleep(20)
    WEnd
    GUICtrlSetData($Label,"Playing")
    Opt("GUIOnEventMode", $oldOneEvent)
    EndFunc

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

    Func _stop()
    $WMP.controls.stop()
    GUICtrlSetData($Label,"Stopped")
    EndFunc

    [/autoit]

    mfg autoBert

  • Ja das funzt schon aber geht das nicht auch ohne GuiGetMsg()? weil ich dachte man sollte guigetcursorinfo() (was ich in meinem eigentlichen script benutze) nicht mit guigetmsg benutzen?

    MfG hellboy

    [autoit]

    Do
    _help($user)
    Until $questions = 0

    [/autoit]

    Meine Werke:
    Ste`s Web-Radio

  • Wenn's dir nur um die Mauskoordinaten geht kannst du auch

    [autoit]

    MouseGetPos

    [/autoit]

    anstatt von der CursorInfo bentuzen. Könnte mir aber auch nur vorstellen, dass es im Advanced-Modus von GuigetMsg Probleme gibt.

    • Offizieller Beitrag

    Alles im OnEventMode:

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $WMP, $Button2, $channel = "http://blackbeats.fm/listen.asx", $Label, $Play = False, $Stop = False

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

    $Form1 = GUICreate("Loop-Stop", 247, 109, 426, 173)
    GUISetOnEvent(-3, "_Exit")
    $WMP = ObjCreate("WMPlayer.OCX")
    $Button1 = GUICtrlCreateButton("Play", 24, 56, 81, 41, 0)
    GUICtrlSetOnEvent(-1, "_play")
    $Button2 = GUICtrlCreateButton("Stop", 128, 56, 81, 41, 0)
    GUICtrlSetOnEvent(-1, "_stop")
    $Label = GUICtrlCreateLabel("Label", 32, 16, 80, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)

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

    While Sleep(50)
    If $Play Then
    $Play = False
    $WMP.URL = $channel
    $WMP.controls.play()
    GUICtrlSetData($Label, "Loading...")
    While $WMP.playstate <> 3 And $Stop = False
    Sleep(20)
    WEnd
    If $Stop Then
    $Stop = False
    Else
    GUICtrlSetData($Label, "Playing")
    EndIf
    EndIf
    WEnd

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

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

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

    Func _play()
    $Play = True
    EndFunc ;==>_play

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

    Func _stop()
    $Stop = True
    $WMP.controls.stop()
    GUICtrlSetData($Label, "Stopped")
    EndFunc ;==>_stop

    [/autoit]

    Edit: Nochmal geändert. Hatte das mit dem Abruch falsch.

    • Offizieller Beitrag

    Na, dann halt mit AdlibRegister:

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

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

    Opt("GUIOnEventMode", 1)

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

    Global $WMP, $Button2, $channel = "http://blackbeats.fm/listen.asx", $Label

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

    $Form1 = GUICreate("Loop-Stop", 247, 109, 426, 173)
    GUISetOnEvent(-3, "_Exit")
    $WMP = ObjCreate("WMPlayer.OCX")
    $Button1 = GUICtrlCreateButton("Play", 24, 56, 81, 41, 0)
    GUICtrlSetOnEvent(-1, "_play")
    $Button2 = GUICtrlCreateButton("Stop", 128, 56, 81, 41, 0)
    GUICtrlSetOnEvent(-1, "_stop")
    $Label = GUICtrlCreateLabel("Label", 32, 16, 80, 20)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)

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

    While Sleep(50)
    WEnd

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

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

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

    Func _play()
    $WMP.URL = $channel
    $WMP.controls.play()
    GUICtrlSetData($Label, "Loading...")
    AdlibRegister('_loadcheck', 20)
    EndFunc ;==>_play

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

    Func _loadcheck()
    If $WMP.playstate = 3 Then
    GUICtrlSetData($Label, "Playing")
    AdlibUnRegister('_loadcheck')
    EndIf
    EndFunc

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

    Func _stop()
    $WMP.controls.stop()
    AdlibUnRegister('_loadcheck')
    GUICtrlSetData($Label, "Stopped")
    EndFunc ;==>_stop

    [/autoit]


    Wichtig ist halt, dass Du die Funktion, die Du über einen Event aufrufst, schnell wieder verlässt, damit ein evtl. anderer Event (Stop-Button) abgearbeitet werden kann.