Handling mit GUICtrlCreateMenu

  • Hallo!
    Ich habe mir ein Menu mit GUICtrlCreateMenu gebastelt und lese die Einträge aus einer INI aus, damit ich neue Einträge variabel hinzufügen kann. Nun stellt sich das Problem, dass ich nicht herausbekomme, auf welches MenuItem ich klicke. Dachte da an @GUI_*. Funktioniert jedoch nicht.

    [autoit]


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

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

    ;Variablen-Deklaration
    $frm_about = "0"

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

    Opt("GUIOnEventMode", 1)

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

    #Region Main_Dialog
    $Localization = GUICreate("Localization %v - RAG Bildung GmbH - %Time , Úte", 460, 410, 273, 250)
    GUISetFont(10, 400, 0, "Verdana")
    $FirmendatenGroup = GUICtrlCreateGroup("Firmendaten", 1, -1, 457, 145)
    $FirmenDatenList = GUICtrlCreateListView("|||", 16, 24, 426, 110)
    GUICtrlSendMsg(-1, 0x101E, 0, 125)
    GUICtrlSendMsg(-1, 0x101E, 1, 50)
    GUICtrlSendMsg(-1, 0x101E, 2, 75)
    GUICtrlSendMsg(-1, 0x101E, 3, 172)
    GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
    $FirmenDatenList_0 = GUICtrlCreateListViewItem("Ansprechpartner:", $FirmenDatenList)
    $FirmenDatenList_1 = GUICtrlCreateListViewItem("Straße:", $FirmenDatenList)
    $FirmenDatenList_2 = GUICtrlCreateListViewItem("Stadt:", $FirmenDatenList)
    $FirmenDatenList_3 = GUICtrlCreateListViewItem("Postleitzahl:", $FirmenDatenList)
    $FirmenDatenList_4 = GUICtrlCreateListViewItem("Telefonnummer:", $FirmenDatenList)
    $FirmenDatenList_5 = GUICtrlCreateListViewItem("Mobilnummer:", $FirmenDatenList)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $ButtonClose = GUICtrlCreateButton("Close", 367, 359, 91, 25, 0)
    GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
    $ServerDatenGroup = GUICtrlCreateGroup("Server-Daten", 1, 145, 457, 209)
    $StandortAuswahl = GUICtrlCreateCombo("Bildungszentrum wählen", 252, 161, 201, 25)
    GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
    $ServerDaten = GUICtrlCreateListView("|Server-Adresse", 16, 192, 426, 150)
    GUICtrlSendMsg(-1, 0x101E, 0, 125)
    GUICtrlSendMsg(-1, 0x101E, 1, 297)
    GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
    $ServerDaten_0 = GUICtrlCreateListViewItem("DNS-Server:", $ServerDaten)
    $ServerDaten_1 = GUICtrlCreateListViewItem("Domäne:", $ServerDaten)
    $ServerDaten_2 = GUICtrlCreateListViewItem("Proxy:", $ServerDaten)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Datei = GUICtrlCreateMenu("&Datei")
    $DataReset = GUICtrlCreateMenuItem("Daten Zurücksetzen", $Datei)
    $MenuItem5 = GUICtrlCreateMenuItem("", $Datei)
    $SpotAdd = GUICtrlCreateMenuItem("Standort Hinzufügen", $Datei)
    $SpotEdit = GUICtrlCreateMenuItem("Standort Editieren", $Datei)
    $SpotDelete = GUICtrlCreateMenuItem("Standort Entfernen", $Datei)
    $MenuItem4 = GUICtrlCreateMenuItem("", $Datei)
    $Close = GUICtrlCreateMenuItem("Schließen", $Datei)
    $MenuStandorte = GUICtrlCreateMenu("&Standorte")
    $Info = GUICtrlCreateMenu("&Info")
    $About = GUICtrlCreateMenuItem("About", $Info)
    $ChangeLog = GUICtrlCreateMenuItem("Changelog", $Info)
    $MenuItem1 = GUICtrlCreateMenuItem("", $Info)
    $Update = GUICtrlCreateMenuItem("Check for Update", $Info)
    GUICtrlSetState(-1, $GUI_DISABLE)
    #EndRegion Main_Dialog
    GUISetState(@SW_SHOW)

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

    #Region GUICtrlSetOnEvents
    ;Main_Menu CTRLs
    GUICtrlSetOnEvent($ButtonClose, "Close")
    GUICtrlSetOnEvent($Close, "Close")
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

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

    ;Standortbuttons
    GUICtrlSetOnEvent($ChangeLog, "test")
    func test()
    MsgBox(0,"",@GUI_CTRLID)
    EndFunc

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

    #EndRegion GUICtrlSetOnEvents

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

    #Region Functions

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

    Init_Menu()
    Func Init_Menu()
    $Standort_Anzahl = IniReadSectionNames("standorte.ini")
    $i = 1
    While $i <= $Standort_Anzahl[0]
    GUICtrlCreateMenuItem($Standort_Anzahl[$i], $MenuStandorte)
    $i = $i + 1
    WEnd
    EndFunc ;==>Init_Menu

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

    Func Close()
    Exit
    EndFunc

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

    #EndRegion Functions

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

    While 1
    Sleep(20)
    WEnd

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

    Hier die Standort.ini:

    Einmal editiert, zuletzt von Wiibrew (2. April 2009 um 09:42)

    • Offizieller Beitrag

    So geht's:

    Spoiler anzeigen
    [autoit]


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

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

    ;Variablen-Deklaration
    $frm_about = "0"

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

    Opt("GUIOnEventMode", 1)

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

    #Region Main_Dialog
    $Localization = GUICreate("Localization %v - RAG Bildung GmbH - %Time , %Date", 460, 410, 273, 250)
    GUISetFont(10, 400, 0, "Verdana")
    $FirmendatenGroup = GUICtrlCreateGroup("Firmendaten", 1, -1, 457, 145)
    $FirmenDatenList = GUICtrlCreateListView("|||", 16, 24, 426, 110)
    GUICtrlSendMsg(-1, 0x101E, 0, 125)
    GUICtrlSendMsg(-1, 0x101E, 1, 50)
    GUICtrlSendMsg(-1, 0x101E, 2, 75)
    GUICtrlSendMsg(-1, 0x101E, 3, 172)
    GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
    $FirmenDatenList_0 = GUICtrlCreateListViewItem("Ansprechpartner:", $FirmenDatenList)
    $FirmenDatenList_1 = GUICtrlCreateListViewItem("Straße:", $FirmenDatenList)
    $FirmenDatenList_2 = GUICtrlCreateListViewItem("Stadt:", $FirmenDatenList)
    $FirmenDatenList_3 = GUICtrlCreateListViewItem("Postleitzahl:", $FirmenDatenList)
    $FirmenDatenList_4 = GUICtrlCreateListViewItem("Telefonnummer:", $FirmenDatenList)
    $FirmenDatenList_5 = GUICtrlCreateListViewItem("Mobilnummer:", $FirmenDatenList)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $ButtonClose = GUICtrlCreateButton("Close", 367, 359, 91, 25, 0)
    GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
    $ServerDatenGroup = GUICtrlCreateGroup("Server-Daten", 1, 145, 457, 209)
    $StandortAuswahl = GUICtrlCreateCombo("Bildungszentrum wählen", 252, 161, 201, 25)
    GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
    $ServerDaten = GUICtrlCreateListView("|Server-Adresse", 16, 192, 426, 150)
    GUICtrlSendMsg(-1, 0x101E, 0, 125)
    GUICtrlSendMsg(-1, 0x101E, 1, 297)
    GUICtrlSetFont(-1, 8, 400, 0, "Verdana")
    $ServerDaten_0 = GUICtrlCreateListViewItem("DNS-Server:", $ServerDaten)
    $ServerDaten_1 = GUICtrlCreateListViewItem("Domäne:", $ServerDaten)
    $ServerDaten_2 = GUICtrlCreateListViewItem("Proxy:", $ServerDaten)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Datei = GUICtrlCreateMenu("&Datei")
    $DataReset = GUICtrlCreateMenuItem("Daten Zurücksetzen", $Datei)
    $MenuItem5 = GUICtrlCreateMenuItem("", $Datei)
    $SpotAdd = GUICtrlCreateMenuItem("Standort Hinzufügen", $Datei)
    $SpotEdit = GUICtrlCreateMenuItem("Standort Editieren", $Datei)
    $SpotDelete = GUICtrlCreateMenuItem("Standort Entfernen", $Datei)
    $MenuItem4 = GUICtrlCreateMenuItem("", $Datei)
    $Close = GUICtrlCreateMenuItem("Schließen", $Datei)
    $MenuStandorte = GUICtrlCreateMenu("&Standorte")
    $Info = GUICtrlCreateMenu("&Info")
    $About = GUICtrlCreateMenuItem("About", $Info)
    $ChangeLog = GUICtrlCreateMenuItem("Changelog", $Info)
    $MenuItem1 = GUICtrlCreateMenuItem("", $Info)
    $Update = GUICtrlCreateMenuItem("Check for Update", $Info)
    GUICtrlSetState(-1, $GUI_DISABLE)
    #EndRegion Main_Dialog
    GUISetState(@SW_SHOW)

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

    #Region GUICtrlSetOnEvents
    ;Main_Menu CTRLs
    ;~ GUICtrlSetOnEvent($About, "Window_About")
    GUICtrlSetOnEvent($ButtonClose, "Close")
    GUICtrlSetOnEvent($Close, "Close")
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

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

    ;Standortbuttons
    ;~ GUICtrlSetOnEvent($ChangeLog, "test")

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

    #EndRegion GUICtrlSetOnEvents

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

    #Region Functions

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

    Init_Menu()

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

    While 1
    Sleep(20)
    WEnd

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

    Func test()
    MsgBox(0, "", $Standort_Anzahl[@GUI_CtrlId-$hMenu[0]+1])
    EndFunc ;==>test

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

    Func Init_Menu()
    ;~ $Standort_Anzahl = IniReadSectionNames("standorte.ini")
    Global $Standort_Anzahl[5] = [4, 'standort1', 'standort2', 'standort3', 'standort4']; nur zum testen

    Global $hMenu[UBound($Standort_Anzahl)]
    For $i = 1 To $Standort_Anzahl[0]
    $hMenu[$i-1] = GUICtrlCreateMenuItem($Standort_Anzahl[$i], $MenuStandorte)
    GUICtrlSetOnEvent(-1, 'test')
    Next
    EndFunc ;==>Init_Menu

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

    Func Close()
    Exit
    EndFunc ;==>Close

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

    #EndRegion Functions

    [/autoit]
  • ich weiß nich genau was du meinst aber statt diesem :

    [autoit]

    While $i <= $Standort_Anzahl[0]
    GUICtrlCreateMenuItem($Standort_Anzahl[$i], $MenuStandorte)
    $i = $i + 1
    WEnd

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

    solltest du eine for schleife benutzten ist um einiges eleganter

    [/autoit]
  • Vielen vielen Dank, Oscar, es funktoniert exakt, wie ich es wollte!
    Nun hätte ich eine reine Verständnisfrage:

    In Line 94 Deines Codes steht

    [autoit]


    GUICtrlSetOnEvent(-1, 'test')

    [/autoit]

    Was macht er mit der vorigen Zeile und weswegen funktioniert es nicht ohne diese Zeile?

  • Okay, hatte die Funktion test übersehen, die Du angefügt hast, danke sehr nochmal!