mehr als 2 GUIs (GUIGETMSG)

  • Hey,

    ich habe folgendes Szenario:

    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 251, 120, -1, -1)
    $Button1 = GUICtrlCreateButton("Make GUI", 48, 32, 155, 49, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $button3 = -1

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

    While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button1
    $Form2 = GUICreate("andere GUI", 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $Button3 = GUICtrlCreateButton("EXIT", 152, 128, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    Case $Button3
    GUIDelete ($nMsg[1])

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

    EndSwitch
    WEnd

    [/autoit]

    Ich möchte, dass jedes Fenster (andere GUI) einzigartig bleibt und trotzdem schließt,
    wenn ich auf EXIT klicke.
    Das Problem ist, dass die GUI neu erstellt wird und somit $Button3 einen neuen Wert bekommt.

    Wie könnte ich das Problem lösen, dass trotzdem immer das Fenster zugeht, wenn ich auch auf EXIT klicke?!

    Vielen Dank schonmal im Voraus

    Gruß Snify

  • Meinst du so ?

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 251, 120, -1, -1)
    $Button1 = GUICtrlCreateButton("Make GUI", 48, 32, 155, 49, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $button3 = -1

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button1
    _gui()
    EndSwitch
    WEnd

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

    Func _gui()
    $Form2 = GUICreate("andere GUI", 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Ceckbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $Button3 = GUICtrlCreateButton("EXIT", 152, 128, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

    While 1
    Switch GUIGETMSG()
    Case -3
    GUISETSTATE(@SW_HIDE,$Form2)
    ExitLoop
    Case $button3
    GUISETSTATE(@SW_HIDE,$Form2)
    ExitLoop
    EndSwitch
    WEnd
    EndFUnc

    [/autoit]
  • Am Anfang des Skriptes alle Gui-Fenster erstellen und dann mit @SW_Hide & @SW_Show die Fenster anzeigen bzw. verstecken.
    Bei Gui-Fenstern, die nur einmal gebraucht werden (z.B. Login-Fenster) kann man per Guidelete das Fenster gleich wieder löschen.

  • nicht ganz.
    Das Problem liegt darin,
    dass sobald ich auf andere GUI klicke eine neue GUI erstellt wird.
    Wenn ich 3 mal klicke, dann kommt 3 mal die gleiche GUI.
    Jetzt möchte ich alle 3 GUIS nacheinander mit dem EXIT Button schließen.
    Ohne dass sich alles schließt.
    Um das zu realisieren, brauch ich etwas, dass jede GUI einzigartig hat und ich damit
    dann die einzelnen GUIs wieder mit dem EXIT Button schließen kann.
    (Ist schwer zu erklären sorry)

    Am Anfang des Skriptes alle Gui-Fenster erstellen und dann mit @SW_Hide & @SW_Show die Fenster anzeigen bzw. verstecken.
    Bei Gui-Fenstern, die nur einmal gebraucht werden (z.B. Login-Fenster) kann man per Guidelete das Fenster gleich wieder löschen.

    Das Problem ist, dass damit der Arbeitsspeicher voll ist. Und außerdem kann es sein, dass die neue GUI erstellt und vielleicht auch nicht. die anderen GUI Fenster sind teils dynamisch und teils statisch. Falls etwas dynamisch wäre, dann nur der TITEL. (der wird vorher bearbeitet).
    Gibt es denn keine andere Möglichkeit? :huh:

  • DU kannst aber keine drei erstellen immer nur eine zweite wenn dann eine dritte und die extra immer mit
    entweder zum beenden GUISETSTATE(@SW_HIDE,$gui) oder GUIDELETE($gui) und darunter immer Exitloop damit autoit in die haupt schleife zurückkehrt

  • Ich hab jetzt mal den Quellcode ein wenig geändert,
    vielleicht ist es dann besser verständlich

    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 251, 120, -1, -1)
    $Button1 = GUICtrlCreateButton("Make GUI", 48, 32, 155, 49, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $button3 = -1
    $i = 0
    While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
    Case $GUI_EVENT_CLOSE
    Exit
    case $Button1
    $i = $i + 1
    $Form2 = GUICreate("andere GUI Nummer: "&$i, 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $Button3 = GUICtrlCreateButton("EXIT", 152, 128, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    Case $Button3
    GUIDelete ($nMsg[1])

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

    EndSwitch
    WEnd

    [/autoit]

    Ich hab jetzt jeder GUI im Titel noch eine Nummer gegeben und gehen davon aus,
    dass jede GUI die gleiche Größe hat und die gleichen Controls etc.
    Allerdings hat jede GUI einen Dynamischen GUI Titel (da ja jede eine Nummer jetzt hat)
    Jetzt möchte ich einfach wenn ich bei EXIT GUI Nummer 2 klicke,
    dass auch GUI Nummer2 zu geht. usw...

  • So?

    Spoiler anzeigen
    [autoit]

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

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

    Dim $array[1]

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

    $array[0] = GUICreate("Form1", 251, 120, -1, -1)
    $Button1 = GUICtrlCreateButton("Make GUI", 48, 32, 155, 49, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    $button3 = -1
    $i = 0

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

    While 1
    $nMsg = GUIGetMsg(1)
    Switch $nMsg[0]
    case $Button1
    $i = $i + 1
    Dim $array[$i + 2]
    $array[$i] = GUICreate("andere GUI Nummer: "&$i, 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $Button3 = GUICtrlCreateButton("EXIT", 152, 128, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)
    Case -3
    $title = WinGetTitle($array)
    If $title = "Form1" then
    Exit
    else
    $split = StringSplit($title,":")
    $name = StringTrimLeft($split[2],1)
    GUISetState(@SW_HIDE,$array[$name])
    Endif

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

    EndSwitch
    WEnd

    [/autoit]
  • hmmm funktioniert nicht wirklich bei mir :-/
    aber ich versuche mal aus dem Code schlau zu werden ;)

    erstmal danke ;)

  • Moin,

    Du hast die Lösung doch schon in deinem ersten Skript stehen !?!

    Spoiler anzeigen
    [autoit]

    While (TRUE)

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

    $nMsg = GUIGetMsg(TRUE)

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

    Switch ($nMsg[0])

    Case $GUI_EVENT_CLOSE
    GUIDelete($nMsg[1]) ; !

    Case $Button1
    $Form2 = GUICreate("andere GUI", 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $Button3 = GUICtrlCreateButton("EXIT", 152, 128, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    Case $Button3
    GUIDelete ($nMsg[1]) ; !

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

    EndSwitch
    WEnd

    [/autoit]


    Gruß
    Greenhorn


  • Ja, warum nicht ?

    In der Schleife war noch ein Bug, so muss die Nachrichtenschleife aussehen, damit Du da auch wieder herauskommst:

    Spoiler anzeigen
    [autoit]

    While (WinExists($Form1)) ; solange das Hauptfenster existiert ...

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

    $nMsg = GUIGetMsg(TRUE)

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

    Switch ($nMsg[0])

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

    Case $Button3
    ContinueCase
    Case $GUI_EVENT_CLOSE
    GUIDelete($nMsg[1]) ; !

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

    Case $Button1
    $Form2 = GUICreate("andere GUI", 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $Button3 = GUICtrlCreateButton("EXIT", 152, 128, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    EndSwitch
    WEnd

    [/autoit]


    Gruß


  • Der Code funktioniert soweit.
    Aber sobald ich den Button ($button3) drücke, geht das Fenster nicht zu.
    über GUI_EVENT_CLOSE gehts wunderbar

  • Also wenn ich folgendes ausführe, dann schliesst sich das zweite Fenster, wenn ich auf EXIT klicke ...

    Spoiler anzeigen
    [autoit]

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

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

    $Form1 = GUICreate("Form1", 251, 120, -1, -1)
    $Button1 = GUICtrlCreateButton("Make GUI", 48, 32, 155, 49, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    $button3 = -1

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

    While (WinExists($Form1)) ; solange das Hauptfenster existiert ...

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

    $nMsg = GUIGetMsg(TRUE)

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

    Switch ($nMsg[0])

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

    Case $Button3
    ContinueCase
    Case $GUI_EVENT_CLOSE
    GUIDelete($nMsg[1]) ; !

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

    Case $Button1
    $Form2 = GUICreate("andere GUI", 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $Button3 = GUICtrlCreateButton("EXIT", 152, 128, 75, 25, $WS_GROUP)
    ;~ GUISetState(@SW_SHOW)

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

    EndSwitch
    WEnd

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

    Exit (0)

    [/autoit]

    EDIT: @simon
    Geht mir auch immer so ... ;)


  • hmmmm also bei mir gehen nur 2 Fenster zu, wenn ich auf EXIT klicke.

    Vielleicht haben wir auch ein Verständnissproblem xDD

    Wenn ich jetzt auf MAKE GUI 20 mal klicke...
    dann geht 20 mal eine NEUE GUI auf.
    Jede NEUE GUI hat einen EXIT Button.

    Wenn ich jetzt irgendeine GUI nehme (von denen 20) und auf EXIT klicke,
    dann geht auch die GUI zu, mit dem Button, auf den ich geklickt habe.

    Also klicke ich im Prinzip auf 20 verschiedene 20 EXIT Buttons und am ENDE ist jede NEUE GUI geschlossen.

    Das ganze funktioniert ja jetzt gut im GUI_EVENT_CLOSE Mode.
    Da klickt man auf das "X" und das Fenster geht zu...

  • Greenhorn
    das problem leigt daran das $Button3 immer das gleiche ist und nicht verschieden

    mein versuch:

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    Dim $array[1]
    $array[0] = 0
    Dim $arr[1]
    $arr[0] = 0
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 251, 120, -1, -1)
    $Button1 = GUICtrlCreateButton("Make GUI", 48, 32, 155, 49, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $Button3 = -1
    $i = 0
    While (WinExists($Form1)) ; solange das Hauptfenster existiert ...

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

    $nMsg = GUIGetMsg(1)

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

    Select
    Case $nMsg[0] = $GUI_EVENT_CLOSE
    GUIDelete($nMsg[1]) ; !
    EndSelect
    Switch $nMsg[0]
    Case $Button1
    $i += 1
    Dim $array[$i + 2]
    Dim $arr[$i + 2]
    $array[0] = $i
    $arr[0] = $i

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

    $arr[$i] = GUICreate("andere GUI", 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $array[$i] = GUICtrlCreateButton("EXIT", 152, 128, 75, 25)
    GUISetState(@SW_SHOW)

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

    EndSwitch
    If $array[0] <> 0 And $arr[0] <> 0 Then
    For $b = 1 To $array[0]
    If $nMsg[0] = $array[$b] Then
    GUIDelete($arr[$b])
    Endif
    next
    Endif

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

    WEnd

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

    Edit:Edit:Edit:Edit:

    Wenn ich es so mache kann man ein fenster zumachen aber kein zweites öffnen

    Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    Dim $array[1]
    $array[0] = 0
    Dim $arr[1]
    $arr[0] = 0
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 251, 120, -1, -1)
    $Button1 = GUICtrlCreateButton("Make GUI", 48, 32, 155, 49, $WS_GROUP)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    $Button3 = -1
    $i = 0
    While (WinExists($Form1)) ; solange das Hauptfenster existiert ...

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

    $nMsg = GUIGetMsg(1)

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

    Select
    Case $nMsg[0] = $GUI_EVENT_CLOSE
    GUIDelete($nMsg[1]) ; !
    EndSelect
    Switch $nMsg[0]
    Case $Button1
    $i += 1
    Dim $array[$i + 2]
    Dim $arr[$i + 2]
    $array[0] = $i
    $arr[0] = $i

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

    $arr[$i] = GUICreate("andere GUI", 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $array[$i] = GUICtrlCreateButton("EXIT", 152, 128, 75, 25)
    GUISetState(@SW_SHOW)

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

    EndSwitch
    If $array[0] <> 0 And $arr[0] <> 0 Then
    For $b = 1 To $array[0]
    If $nMsg[0] = $array[$b] Then
    GUIDelete($nMsg[1])
    Endif
    next
    Endif

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

    WEnd

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

    Einmal editiert, zuletzt von simon (25. September 2009 um 17:21)

  • So funktioniert es bei mir ...

    Spoiler anzeigen
    [autoit]

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

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

    Global $IDC_EXIT [1] ; Hier die IDs der "EXIT" Schaltflächen speichern

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

    $Form1 = GUICreate("Form1", 251, 120, -1, -1)
    $Button1 = GUICtrlCreateButton("Make GUI", 48, 32, 155, 49, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    While (WinExists($Form1)) ; solange das Hauptfenster existiert ...

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

    Local $nMsg
    Local $i

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

    $nMsg = GUIGetMsg(TRUE)

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

    Switch $nMsg[0]

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

    Case 0
    ContinueLoop

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

    Case $GUI_EVENT_CLOSE
    GUIDelete($nMsg[1])

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

    Case $Button1

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

    $i = UBound($IDC_EXIT)

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

    ReDim $IDC_EXIT[$i + 1]
    $IDC_EXIT[0] = $i

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

    GUICreate("andere GUI", 246, 166, 192, 124)
    $Button2 = GUICtrlCreateButton("Button", 32, 80, 75, 25, $WS_GROUP)
    $Label2 = GUICtrlCreateLabel("LABEL", 64, 16, 37, 17)
    $Checkbox2 = GUICtrlCreateCheckbox("Control", 120, 40, 97, 17)
    $IDC_EXIT[$i] = GUICtrlCreateButton("EXIT", 152, 128, 75, 25)
    GUISetState(@SW_SHOW)

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

    Case Else

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

    If ($IDC_EXIT[0]) Then

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

    For $i = 1 To $IDC_EXIT[0]

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

    If ($nMsg[0] == $IDC_EXIT[$i]) Then _
    GUIDelete($nMsg[1])
    Next
    EndIf
    EndSwitch

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

    WEnd

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

    Exit (0)

    [/autoit]


    Gruß
    Greenhorn