GUIGetMsg gibt falsche Werte zurück

  • Tach zusammen

    Also ich hab das Skript von gestern etwas weitergeführt und stehe erneut vor einem Problem.
    Was SOLLTE passieren:
    Sobald man in der ersten GUI den Button klickt, öffnet sich eine neue GUI, von der aus geht es dann über einen weiteren Button auf die nächste usw.
    Was passiert:
    Sobald man den ersten Button anklickt, öffnet sich nicht nur die erste GUI sondern auch gleich die zweite.
    Meine Vermutung:
    Es scheint so, als ob in der zweiten GUI das GUIGetMsg schon beim ersten durchlauf zurückgibt, dass der Button gedrückt wurde.
    Um das zu veranschaulichen habe ich eine MsgBox an den Punkt gesetzt an dem eigentlich der Button gedrückt werden muss damit das Programm dorthin springt.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <Misc.au3>
    #include <GUICtrlPic.au3>
    #include <File.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>

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

    Global $ButtonX1 = ((@DesktopWidth / 2) - 313) + 480 ;Calculates the position where the button-area starts on the x-axis
    Global $ButtonX2 = ((@DesktopWidth / 2) - 313) + (480 + 130) ;Calculates the position where the button-area ends on the x-axis
    Global $ButtonY1 = ((@DesktopHeight / 2) - 206) + 360 ;Calculates the position where the button-area starts on the y-axis
    Global $ButtonY2 = ((@DesktopHeight / 2) - 206) + (360 + 40) ;Calculates the position where the button-area ends on the y-axis
    Global $test = 0 ;Used later to prevent the hover from flickering
    Global $Terms ;Array that will later contain the "Terms of Use"-Text

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

    $Form2 = GUICreate("", 626, 412, -1, -1, BitOR($WS_SYSMENU,$WS_POPUP), BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE));Creates a new interface without any interaction-possibility
    $Label = GUICtrlCreateLabel("", 480, 360, 130, 40)
    $Pic1 = GUICtrlCreatePic(@ScriptDir &"\Backgrnd.jpg", 0, 0, 626, 412) ;Creates the background picture
    $Pic2 = _GUICtrlPic_Create(@ScriptDir &"\Button.png", 480, 360, 130, 40) ;Creates another picture (with a transparent channel)
    GUISetState(@SW_SHOW) ;Shows the interface
    While 1
    _mover($Pic2, @ScriptDir &"\Button.png", @ScriptDir &"\Button_Hover.png") ;Creates a "hover"-effect on the button-picture
    $nMsg = GUIGetMsg()
    $mPos = GUIGetCursorInfo()
    Select
    Case $mPos[0] >= 480 And $mPos[0] <= 610 And $mPos[1] >= 360 And $mPos[1] <= 400 And _IsPressed(01)
    Terms()
    ExitLoop
    Case $nMsg = $GUI_EVENT_CLOSE
    Exit
    EndSelect
    ;~ ToolTip($mPos[0] & " - " & $mPos[1]) ;Shows the coordinates of the cursor as tooltip
    WEnd

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

    Terms()

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

    Func _mover($control, $bild1, $bild2) ;Function to create a "hover"-effect on the chosen picture
    $mpos = GUIGetCursorInfo()
    If (IsArray($mpos)) Then
    If ($mpos[4] = $control) Then
    If $test = 0 Then
    $test = 1
    _GUICtrlPic_SetImage($control, $bild2)
    EndIf
    Else
    If $test = 1 Then
    $test = 0
    _GUICtrlPic_SetImage($control, $bild1)
    EndIf
    EndIf
    EndIf
    EndFunc

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

    Func Terms()
    GUIDelete($Form2)
    ;~ $Term = FileOpen(@ScriptDir &"\ToU.term")
    ;~ _FileReadToArray($Term, $Terms)
    $Form1_1 = GUICreate("CryInstaller - ", 615, 438, -1, -1)
    GUISetBkColor(0x000000)
    $Button11 = GUICtrlCreateButton("Accept", 530, 405, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFF0000)
    $Button12 = GUICtrlCreateButton("Refuse", 445, 405, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFF0000)
    $Label1 = GUICtrlCreateLabel("Terms of Use:", 10, 120, 83, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    $Edit1 = GUICtrlCreateEdit("", 10, 140, 595, 259, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
    GUICtrlSetData(-1, "")
    $Pic1 = GUICtrlCreatePic(@ScriptDir &"\Default_Header.jpg", 0, 0, 615, 111)
    GUISetState(@SW_SHOW)
    While 1
    $Msg = GUIGetMsg()
    Switch $Msg
    Case $Button11
    MsgBox(0, "", "Test")
    FolderSettings()
    GUIDelete($Form1_1)
    Case $Button12
    ExitInstall()
    Case $GUI_EVENT_CLOSE
    ExitInstall()
    EndSwitch
    WEnd
    EndFunc

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

    Func FolderSettings()
    $Form1_2 = GUICreate("CryInstaller - ", 615, 438, -1, -1)
    GUISetBkColor(0x000000)
    $Button21 = GUICtrlCreateButton("Start", 530, 405, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFF0000)
    $Button22 = GUICtrlCreateButton("Exit", 445, 405, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFF0000)
    $Input1 = GUICtrlCreateInput("", 30, 330, 476, 21)
    $Pic1 = GUICtrlCreatePic(@ScriptDir &"\Default_Header.jpg", 0, 0, 611, 111)
    $Button23 = GUICtrlCreateButton("Suchen...", 505, 330, 75, 25)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFF0000)
    $Checkbox1 = GUICtrlCreateCheckbox("Add desktop shortcut", 30, 285, 127, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    $Checkbox2 = GUICtrlCreateCheckbox("Launch after installation", 30, 250, 152, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUISetState(@SW_SHOW)
    While 1
    $nsg = GUIGetMsg()
    Switch $nsg

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

    Case $GUI_EVENT_CLOSE
    ExitInstall()
    EndSwitch
    WEnd
    EndFunc

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

    Func Installation()

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

    EndFunc

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

    Func ExitInstall()
    $Message = MsgBox(52, "Are you sure?", "This will stop and exit the installation. Do you really want to exit this?")
    If $Message = 6 Then
    Exit
    EndIf
    EndFunc

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

    Func ValidateCrysis()

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

    EndFunc

    [/autoit]

    (Vorsichtshalber hab ich diesmal im .zip die GUICtrlPic-UDF gleich integriert.)

    PS: Ich weiss, dass ich da noch ein paar leere Funktionen habe...die bekommen dann schon noch nen Inhalt ;)

  • Ich würde es mal mit GUIGetMsg(1) versuchen und auch noch überprüfen ob die Message überhaupt vom 2. Fenster kommt. GUISwitch() sollte auch gehen. Vielleicht hilft das.

    Gruss Shadowigor

  • Also wenn ich GUIGetMsg(1) mache, dann hängt das Programm...GUISwitch($Form1_1) hat auch nichts gebracht...komisch ist, dass ich den genau gleichen Vorgang später nochmals mache...dort funktioniert es plötzlich 8|

    Bild1: Ich beim debuggen

    • Offizieller Beitrag

    Ein Tipp:
    - alle GUI am Anfang erstellen
    - bei Bedarf mit GuiSetState @SW_SHOW / @SW_HIDE ein-/ausblenden

    Zu deinem Problem:
    Es sieht so aus, als ob die Bedingung für den Aufruf der Funktion schon beim Start zutrifft. Hast du das mal überprüft? (Ausgabe der Koordinaten in die Konsole zum Direktabgleich)
    Mir scheint aber auch, dass du völlig falsche Koordinaten abgleichst. Was dort für den bereich, über dem sich die Maus befinden soll, angegeben ist macht irgendwie nicht recht Sinn.

  • Funktioniert aber so (es ist etwas kompliziert geschrieben weil es "prässiert" hat (sorry mir kommt das deutsche Wort dafür gerade nicht).
    Mein Problem befindet sich allerdings auch erst in der Funktion Terms(). Sobald die gui erstellt wurde und das Programm in der schlaufe steckt, gibt es an das der Button bereits geklickt wird.

    Das mit den GUIs am Anfang ist aber eg. ne gute Idee...werds zuhause mal versuchen.

    Bild1: Ich beim debuggen

  • Ich bin mir nicht genau sicher was du meinst, aber ich glaube du möchtest sowas?

    Gui in Gui
    [autoit]


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

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

    $Form1 = GUICreate('test', 230, 107, 579, 292)
    $Weiter = GUICtrlCreateButton("Weiter", 24, 40, 75, 25, $WS_GROUP)
    $Exit = GUICtrlCreateButton("Exit", 128, 40, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Weiter
    GUISetState(@SW_HIDE,$Form1)
    _Weiter()
    Case $Exit
    Exit

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

    EndSwitch
    WEnd

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

    Func _Weiter()
    $Form2 = GuiCreate('test1',230,107,579,292)
    $Weiter2 = GUICtrlCreateButton("Weiter", 24, 40, 75, 25, $WS_GROUP)
    $Exit = GUICtrlCreateButton("Exit", 128, 40, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW,$Form2)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Weiter2
    GUISetState(@SW_HIDE,$Form2)
    _Weiter1()
    Case $Exit
    Exit

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

    EndSwitch
    WEnd
    EndFunc

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

    Func _Weiter1()

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

    $Form3 = GuiCreate('test2',230,107,579,292)
    $Fin = GUICtrlCreateButton("Finish", 24, 40, 75, 25, $WS_GROUP)
    $Exit = GUICtrlCreateButton("Exit", 128, 40, 75, 25, $WS_GROUP)
    GUISetState(@SW_SHOW,$Form3)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Fin
    Exit
    Case $Exit
    Exit

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

    EndSwitch
    WEnd
    EndFunc

    [/autoit]

    Verschiedene GUI's die weiterführend sind und nach dem "Weiter" die Alte Gui verschwindet, seh ich dass richtig?
    Hab ich mal schnelle zam gezimmert.

    Btw, Das Deutsche Wort zu "Prässiert" ist "Pressant", also, eilig / Stressig und so :D
    "Hallo Landsbruder haha :D"

    • Offizieller Beitrag

    Ja das ist genau was ich versucht habe...aber bei mir ging es auf diese Art nicht ö.Ö


    Wie schon gesagt: Auf diese Art und Weise sollst du es ja keinesfalls tun. Erst alle GUI erstellen.
    Hier ein Bsp.:

    Spoiler anzeigen
    [autoit]

    Local $gui1, $gui2, $gui3, $gui4, $gui5, $btn1_1, $btn1_2, $btn1_3, $btn1_4, $btn2, $btn3, $btn4, $btn5, $msg

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

    $gui1 = GUICreate('GUI 1')
    $btn1_1 = GUICtrlCreateButton('Zeige GUI 2', 10, 20, 100, 20)
    $btn1_2 = GUICtrlCreateButton('Zeige GUI 3', 10, 50, 100, 20)
    $btn1_3 = GUICtrlCreateButton('Zeige GUI 4', 10, 80, 100, 20)
    $btn1_4 = GUICtrlCreateButton('Zeige GUI 5', 10, 110, 100, 20)

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

    $gui2 = GUICreate('GUI 2')
    $btn2 = GUICtrlCreateButton('Button 2', 10, 20, 100, 20)

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

    $gui3 = GUICreate('GUI 3')
    $btn3 = GUICtrlCreateButton('Button 3', 10, 20, 100, 20)

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

    $gui4 = GUICreate('GUI 4')
    $btn4 = GUICtrlCreateButton('Button 4', 10, 20, 100, 20)

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

    $gui5 = GUICreate('GUI 5')
    $btn5 = GUICtrlCreateButton('Button 5', 10, 20, 100, 20)

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

    GUISetState(@SW_SHOW, $gui1)

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

    While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1] ; Window Handle
    Case $gui1
    Switch $msg[0] ; Event
    Case $GUI_EVENT_CLOSE
    ExitLoop
    Case $btn1_1
    GUISetState(@SW_HIDE, $gui1)
    GUISetState(@SW_SHOW, $gui2)
    Case $btn1_2
    GUISetState(@SW_HIDE, $gui1)
    GUISetState(@SW_SHOW, $gui3)
    Case $btn1_3
    GUISetState(@SW_HIDE, $gui1)
    GUISetState(@SW_SHOW, $gui4)
    Case $btn1_4
    GUISetState(@SW_HIDE, $gui1)
    GUISetState(@SW_SHOW, $gui5)
    EndSwitch
    Case $gui2
    Switch $msg[0]
    Case $GUI_EVENT_CLOSE
    GUISetState(@SW_SHOW, $gui1)
    GUISetState(@SW_HIDE, $gui2)
    Case $btn2
    MsgBox(0, '', 'Button 2 geklickt')
    EndSwitch
    Case $gui3
    Switch $msg[0]
    Case $GUI_EVENT_CLOSE
    GUISetState(@SW_SHOW, $gui1)
    GUISetState(@SW_HIDE, $gui3)
    Case $btn3
    MsgBox(0, '', 'Button 3 geklickt')
    EndSwitch
    Case $gui4
    Switch $msg[0]
    Case $GUI_EVENT_CLOSE
    GUISetState(@SW_SHOW, $gui1)
    GUISetState(@SW_HIDE, $gui4)
    Case $btn4
    MsgBox(0, '', 'Button 4 geklickt')
    EndSwitch
    Case $gui5
    Switch $msg[0]
    Case $GUI_EVENT_CLOSE
    GUISetState(@SW_SHOW, $gui1)
    GUISetState(@SW_HIDE, $gui5)
    Case $btn5
    MsgBox(0, '', 'Button 5 geklickt')
    EndSwitch
    EndSwitch
    WEnd

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

    GUIDelete($gui1)
    GUIDelete($gui2)
    GUIDelete($gui3)
    GUIDelete($gui4)
    GUIDelete($gui5)

    [/autoit]