Kann man 2 Schleifen irgendwie Parallel laufen lassen?

  • Hallo Community,
    ich habe ein Skript geschrieben, um zu beobachten wann bestimmte Computer Online sind.
    Hier erstmal das Skript:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>

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

    HotKeySet ("{END}", "stop")

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

    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Wer ist Online?", 611, 340, 366, 327, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
    $Label1 = GUICtrlCreateLabel("Welcher PC ist Online?", 104, 32, 382, 41)
    GUICtrlSetFont(-1, 24, 800, 2, "Lucida Fax")
    $Label2 = GUICtrlCreateLabel("Benedikt", 192, 104, 105, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label3 = GUICtrlCreateLabel("Franzsika", 192, 144, 114, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label4 = GUICtrlCreateLabel("Max", 192, 184, 51, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label5 = GUICtrlCreateLabel("Victoria", 192, 224, 99, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label6 = GUICtrlCreateLabel("Mama", 192, 264, 68, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Franziska = GUICtrlCreateLabel("Online", 352, 144, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Mama = GUICtrlCreateLabel("Online", 352, 264, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Max = GUICtrlCreateLabel("Online", 352, 184, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Victoria = GUICtrlCreateLabel("Online", 352, 224, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Benedikt = GUICtrlCreateLabel("Online", 352, 104, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    GuiCtrlSetData ($Benedikt, "Offline")
    GuiCtrlSetColor($Benedikt, 0xff0000)
    GuiCtrlSetData ($Franziska, "Offline")
    GuiCtrlSetColor ($Franziska, 0xff0000)
    GuiCtrlSetData ($Max, "Offline")
    GuiCtrlSetColor ($Max, 0xff0000)
    GuiCtrlSetData ($Victoria, "Offline")
    GuiCtrlSetColor ($Victoria, 0xff0000)
    GuiCtrlSetData ($Mama, "Offline")
    GuiCtrlSetColor ($Mama, 0xff0000)

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

    While 1
    If Not Ping("Maximilian") = 0 Then
    GuiCtrlSetData ($Max, "Online")
    GuiCtrlSetColor ($Max, 0x00ff00)
    EndIf
    If Not Ping("Franziska") = 0 Then
    GuiCtrlSetData ($Franziska, "Online")
    GuiCtrlSetColor ($Franziska, 0x00ff00)
    EndIf
    If Not Ping ("BENNE-PC") = 0 Then
    GuiCtrlSetData ($Benedikt, "Online")
    GuiCtrlSetColor ($Benedikt, 0x00ff00)
    If Not Ping ("VICI-PC") = 0 Then
    GuiCtrlSetData ($Victoria, "Online")
    GuiCtrlSetColor ($Victoria, 0x00ff00)
    EndIf
    If Not Ping ("SYLVIA-PC") = 0 Then
    GuiCtrlSetData ($Mama, "Online")
    GuiCtrlSetColor ($Mama, 0x00ff00)
    EndIf
    Sleep (100)
    WEnd

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

    Func stop()
    Exit
    EndFunc

    [/autoit]


    Wie ihr seht, wird dauerhaft überprüft, welcher Computer Online/Offline ist.

    Nun wollte ich es so machen,
    dass wenn ich auf einen Namen klicke also auf das Label, dann soll bei dem Computer alles minimiert werden und ne MsgBox kommen, so von wegen: "Es ist zu spät, mach bitte aus!"
    Naja, per TCP send wird eben der Befehl gesendet und so weiter..
    Das ist aber nicht mein Problem!
    Sondern, muss ja die Schleife zur Überprüfung OB jemand Online ist laufen und dazu gleichzeitig die Schleife, mit der ich die Funktion auf dem Labelclick abrufe.
    Also sowas:

    [autoit]

    While 1
    ;Switch etc
    Case $Label1
    ;....
    EndSwitch
    WEnd

    [/autoit]

    Gibt es dafür eine Lösung???

    Edit: Spoiler gesetzt ;)

    Danke schonmal,

  • Hi,
    der Oneventmode ist dein Freund^^
    Du lässt die Schleife genau wie in deinem Script laufen und bei einem Klick auf den "Senden"-Button wird die Funktion "Senden" aufgerufen...
    ciao
    Andy

  • Danke für die Antworten!
    So sieht mein aktuelles Skript aus:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>

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

    HotKeySet ("{END}", "stop")

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

    AdlibEnable ("_OnlineCheck", 2000)

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

    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Wer ist Online?", 611, 340, 366, 327, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
    $Label1 = GUICtrlCreateLabel("Welcher PC ist Online?", 104, 32, 382, 41)
    GUICtrlSetFont(-1, 24, 800, 2, "Lucida Fax")
    $Label2 = GUICtrlCreateLabel("Benedikt", 192, 104, 105, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label3 = GUICtrlCreateLabel("Franzsika", 192, 144, 114, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label4 = GUICtrlCreateLabel("Max", 192, 184, 51, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label5 = GUICtrlCreateLabel("Victoria", 192, 224, 99, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label6 = GUICtrlCreateLabel("Mama", 192, 264, 68, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Franziska = GUICtrlCreateLabel("Online", 352, 144, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Mama = GUICtrlCreateLabel("Online", 352, 264, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Max = GUICtrlCreateLabel("Online", 352, 184, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Victoria = GUICtrlCreateLabel("Online", 352, 224, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Benedikt = GUICtrlCreateLabel("Online", 352, 104, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    GuiCtrlSetData ($Benedikt, "Offline")
    GuiCtrlSetColor($Benedikt, 0xff0000)
    GuiCtrlSetData ($Franziska, "Offline")
    GuiCtrlSetColor ($Franziska, 0xff0000)
    GuiCtrlSetData ($Max, "Offline")
    GuiCtrlSetColor ($Max, 0xff0000)
    GuiCtrlSetData ($Victoria, "Offline")
    GuiCtrlSetColor ($Victoria, 0xff0000)
    GuiCtrlSetData ($Mama, "Offline")
    GuiCtrlSetColor ($Mama, 0xff0000)

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

    _OnlineCheck()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Label2
    MsgBox (1, "", "Test")
    EndSwitch
    WEnd

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

    Func _OnlineCheck()
    If Not Ping("Maximilian") = 0 Then
    GuiCtrlSetData ($Max, "Online")
    GuiCtrlSetColor ($Max, 0x00ff00)
    EndIf
    If Not Ping("Franziska") = 0 Then
    GuiCtrlSetData ($Franziska, "Online")
    GuiCtrlSetColor ($Franziska, 0x00ff00)
    EndIf
    If Not Ping ("BENNE-PC") = 0 Then
    GuiCtrlSetData ($Benedikt, "Online")
    GuiCtrlSetColor ($Benedikt, 0x00ff00)
    EndIf
    If Not Ping ("VICI-PC") = 0 Then
    GuiCtrlSetData ($Victoria, "Online")
    GuiCtrlSetColor ($Victoria, 0x00ff00)
    EndIf
    If Not Ping ("SYLVIA-PC") = 0 Then
    GuiCtrlSetData ($Mama, "Online")
    GuiCtrlSetColor ($Mama, 0x00ff00)
    EndIf
    EndFunc

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

    Func stop()
    Exit
    EndFunc

    [/autoit]

    Jedoch reagiert das Skript sehr träge!
    Also wenn ich zum Beispiel das Fenster mit der Maus "Wegziehen" will.
    Dann dauert es seine Zeit bis das überhaupt ausgeführt wird..
    Gibt es dafür eine Lösung?


    Außerdem, wie kann ich einen Klick auf ein Label abfragen? ^^
    Falls das überhaupt geht..

    [autoit]

    Case $Label2

    [/autoit]

    Geht zumindest nicht.

    Sorry ich bomb euch hier mit Fragen zu ^^

  • Ja man kann einen click und auch einen Doppelklick auf ein Label abfragen und zwar so:

    Spoiler anzeigen
    [autoit]

    Opt("MustDeclareVars", 1)

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

    Global $gui, $label, $WM_COMMAND = 0x0111

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

    $gui = GUICreate("TEST", 200, 100)
    $label = GUICtrlCreateLabel("Test Label", 5, 5)
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

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

    GUISetState()

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

    Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $iCode, $hlabel
    $iCode = BitShift($iwParam, 16)

    If Not IsHWnd($label) Then $hlabel = GUICtrlGetHandle($label)

    Switch $ilParam
    Case $label, $hlabel

    Switch $iCode
    Case 0
    MsgBox(0, "", "Klick auf das Label")

    Case 1
    MsgBox(0, "", "Doppelklick auf das Label") ;Funktioniert so nicht da davor die MsgBox vom normalen klick kommt, zum testen die obere MsgBox mal auskommentieren

    EndSwitch

    EndSwitch
    EndFunc

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

    Do
    Until GUIGetMsg() = -3

    [/autoit]

    MFG FireFlyer

    *Paradox ist, wenn man sich im Handumdrehen den Fuss bricht* :D

  • Ist die Funktion _Onlinecheck überhaupt nach 2 Sekunden fertig? Nee oder? Die Ping Funktion ist doch relativ träge.

    Ein Klick aufs Label funktioniert doch schon per default, möglicherweise liegt das am Zusammenspiel mit der anderen Funktion
    So funktioniert der Klick:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsex.au3>
    #include <WindowsConstants.au3>

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

    #Region ### START Koda GUI section ###
    $Form1 = GUICreate("Wer ist Online?", 611, 340, 366, 327, BitOR($WS_EX_TOOLWINDOW, $WS_EX_WINDOWEDGE))
    $Label1 = GUICtrlCreateLabel("Welcher PC ist Online?", 104, 32, 382, 41)
    GUICtrlSetFont(-1, 24, 800, 2, "Lucida Fax")
    $Label2 = GUICtrlCreateLabel("Benedikt", 192, 104, 105, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label3 = GUICtrlCreateLabel("Franzsika", 192, 144, 114, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label4 = GUICtrlCreateLabel("Max", 192, 184, 51, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label5 = GUICtrlCreateLabel("Victoria", 192, 224, 99, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Label6 = GUICtrlCreateLabel("Mama", 192, 264, 68, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Franziska = GUICtrlCreateLabel("Online", 352, 144, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Mama = GUICtrlCreateLabel("Online", 352, 264, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Max = GUICtrlCreateLabel("Online", 352, 184, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Victoria = GUICtrlCreateLabel("Online", 352, 224, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    $Benedikt = GUICtrlCreateLabel("Online", 352, 104, 120, 31)
    GUICtrlSetFont(-1, 16, 400, 0, "Showcard Gothic")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    GuiCtrlSetData ($Benedikt, "Offline")
    GuiCtrlSetColor($Benedikt, 0xff0000)
    GuiCtrlSetData ($Franziska, "Offline")
    GuiCtrlSetColor ($Franziska, 0xff0000)
    GuiCtrlSetData ($Max, "Offline")
    GuiCtrlSetColor ($Max, 0xff0000)
    GuiCtrlSetData ($Victoria, "Offline")
    GuiCtrlSetColor ($Victoria, 0xff0000)
    GuiCtrlSetData ($Mama, "Offline")
    GuiCtrlSetColor ($Mama, 0xff0000)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Label2
    MsgBox (1, "", "Test")
    EndSwitch
    WEnd

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

    Func stop()
    Exit
    EndFunc

    [/autoit]
  • Eine weitere Möglichkeit die ich aber nicht so gut finde da sie wohl schlechter von der Performance ist.
    Diese Möglichkeit ist eher dazu geeignet um ein Hovern abzufragen. Wenn du z.b. möchtest das sich das Label verändert wenn die Maus drüber ist.

    Spoiler anzeigen
    [autoit]

    Opt("MustDeclareVars", 1)

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

    Global $gui, $label, $mouse

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

    $gui = GUICreate("TEST", 200, 100)
    $label = GUICtrlCreateLabel("Test Label", 5, 5)

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

    GUISetState()

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

    Do
    $mouse = GUIGetCursorInfo()
    ;Wenn $mouse ein Array ist UND $mouse über dem Label ist UND $mouse den Button 1 gedrückt hat DANN -->
    If IsArray($mouse) And $mouse[4] = $label And $mouse[2] = 1 Then MsgBox(0, "", "Klick auf das Label")

    Until GUIGetMsg() = -3

    [/autoit]

    MFG FireFlyer

    *Paradox ist, wenn man sich im Handumdrehen den Fuss bricht* :D

  • $SS_NOTIFY reicht doch ;)
    s. Hilfe zu GUICtrlCreateLabel (forced style = $SS_NOTIFY & $SS_LEFT)

    Und beim Doppelklick dann die Variante (die erste) von Fireflyer nur ohne den einfachen abzufangen.

    • Offizieller Beitrag

    Die Funktion "_OnlineCheck" würde ich lieber so schreiben:

    Spoiler anzeigen
    [autoit]


    Func _OnlineCheck()
    TCPStartup()
    If TCPNameToIP("Maximilian") <> "" Then
    GUICtrlSetData($Max, "Online")
    GUICtrlSetColor($Max, 0x00ff00)
    Else
    GUICtrlSetData($Max, "Offline")
    GUICtrlSetColor($Max, 0xff0000)
    EndIf
    If TCPNameToIP("Franziska") <> "" Then
    GUICtrlSetData($Franziska, "Online")
    GUICtrlSetColor($Franziska, 0x00ff00)
    Else
    GUICtrlSetData($Franziska, "Offline")
    GUICtrlSetColor($Franziska, 0xff0000)
    EndIf
    If TCPNameToIP("BENNE-PC") <> "" Then
    GUICtrlSetData($Benedikt, "Online")
    GUICtrlSetColor($Benedikt, 0x00ff00)
    Else
    GUICtrlSetData($Benedikt, "Offline")
    GUICtrlSetColor($Benedikt, 0xff0000)
    EndIf
    If TCPNameToIP("VICI-PC") <> "" Then
    GUICtrlSetData($Victoria, "Online")
    GUICtrlSetColor($Victoria, 0x00ff00)
    Else
    GUICtrlSetData($Victoria, "Offline")
    GUICtrlSetColor($Victoria, 0xff0000)
    EndIf
    If TCPNameToIP("SYLVIA-PC") <> "" Then
    GUICtrlSetData($Mama, "Online")
    GUICtrlSetColor($Mama, 0x00ff00)
    Else
    GUICtrlSetData($Mama, "Offline")
    GUICtrlSetColor($Mama, 0xff0000)
    EndIf
    TCPShutdown()
    EndFunc ;==>_OnlineCheck

    [/autoit]


    TCPNameToIP ist deutlich schneller als Ping. Wenn der PC online ist ganz besonders.

  • Vielen Vielen Dank für die ganzen Hilfen !
    Ich werde versuchen die Tips zu verarbeiten :rolleyes:

    Wenns Probleme gibt, die ich nicht lösen kann, dann meld ich mich !