Buttons und Run

  • hallo,

    hab erst vor einigen tagen mit autoit angefangen.
    jetzt hab ich mir ein kleines script geschrieben, mit dem ordner aufgelistet werden. die darin befindliche txt-datei werden eingelesen und in einem edit-feld angezeigt.
    befindet sich in dem ordner eine exe-datei wird ein button erstellt.

    jetzt zu meinem problem. wie kann ich diese exe-dateien mit klick auf den button ausführen lassen?
    UICtrlSetOnEvent erlaubt ja keine parameter. stehe auf dem schlauch. vieleicht weis ja einer von euch wie man so was umsetzen kann.

    hier mal mein script bisher:

    [autoit]

    #include <GuiConstants.au3>
    #include <file.au3>

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

    Opt("GUIOnEventMode", 1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")

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

    $Folders = _FileListToArray(@ScriptDir, "*", 2)

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

    GuiCreate("Serial/Keygen", 500, ($Folders[0]*25)+50,0,0, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetState()
    $top = 10
    $closebutton = GUICtrlCreateButton("Schließen", 150, ($Folders[0]*25)+20, 60)
    GUICtrlSetOnEvent(-1, "Close")
    For $i = 1 to $Folders[0] Step 1
    $Label = GuiCtrlCreateLabel($Folders[$i], 10, $top)
    $FileType = _FileListToArray(@ScriptDir&"\"&$Folders[$i], "*", 1)
    if $FileType[0]>0 Then
    If StringRight($FileType[1], 3) = "txt" Then
    $file = FileOpen(@ScriptDir&"\"&$Folders[$i]&"\"&$FileType[1], 0)
    $FileText = FileRead($file)
    $Input = GUICtrlCreateEdit($FileText, 150, $top , 350, 20)
    FileClose($file)
    ElseIf StringRight($FileType[1], 3) = "exe" Then
    $startbutton = GUICtrlCreateButton("KeyGen", 150, $top, 50, 20)
    GUICtrlSetOnEvent(-1, "KeyGen")
    EndIf
    Else
    $Label = GuiCtrlCreateLabel("Andere", 150, $top)
    EndIf
    $top = $top + 25
    Next

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

    While 1
    Sleep(10)
    Wend

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

    Func Close()
    Exit
    EndFunc

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

    Func KeyGen()
    Exit
    EndFunc

    [/autoit]

    GUISetOnEvent($GUI_EVENT_CLOSE, "Close") funktioniert leider auch nicht. jemand ne idee warum?

    bernd670 - Zur Code-Darstellung bitte nicht die Code-Tags sondern die AutoIt-Tags vervenden!

    Einmal editiert, zuletzt von Byte (21. September 2006 um 10:10)

  • Ich geb ehrlich zu das ich mich nicht wirklich mit deinem Skript beschäftigt habe.

    Hier aber mal ein Beispiel wie das mit den exen funktionieren könnte:

    [autoit]

    #include <GUIConstants.au3>
    #include <File.au3>

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

    $Exen = _FileListToArray(@ScriptDir & "\", "*.exe", 1)
    $ButtonAnz = $Exen[0]

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

    $WindowHigh = $ButtonAnz*20+28
    $ButtonPlatz = 0

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

    $Form1 = GUICreate("Test", 250, $WindowHigh)

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

    For $r = 1 To $ButtonAnz Step 1

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

    $ButtonPlatz = $ButtonPlatz + 20
    Assign ( "Button" & $r, GUICtrlCreateButton(StringTrimRight($Exen[$r],4), 8, $ButtonPlatz, 235, 17), 2 )

    Next

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

    GUISetState(@SW_SHOW)

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

    While 1
    $msg = GuiGetMsg()

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

    For $r = 1 To $ButtonAnz Step 1

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

    If IsDeclared("Button" & $r) Then
    If $msg = Eval("Button" & $r) Then
    Run($Exen[$r], @WorkingDir)
    EndIf
    EndIf
    Next

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

    Select
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    EndSelect
    WEnd
    Exit

    [/autoit]

    Vielleicht hilfts dir weiter.

    Einmal editiert, zuletzt von AspirinJunkie (21. September 2006 um 10:44)

  • vielen dank für deine anregung. habe es hinbekommen, läuft prächtig.

    Spoiler anzeigen
    [autoit]

    #include <GuiConstants.au3>
    #include <file.au3>

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

    $Folders = _FileListToArray(@ScriptDir, "*", 2)
    $Exen = $Folders
    For $y = 1 To $Exen[0] Step 1
    $Exen[$y] = ''
    Next
    $ButtonAnz = $Exen[0]

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

    $Form1 = GuiCreate("Serial/Keygen", 500, ($Folders[0]*25)+50,0,0, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS, $DS_SETFOREGROUND))
    WinSetOnTop($Form1, "", 1)

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

    $closebutton = GUICtrlCreateButton("Schließen", 150, ($Folders[0]*25)+20, 60)
    $top = 10

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

    For $i = 1 to $Folders[0] Step 1
    $Label = GuiCtrlCreateLabel($Folders[$i], 10, $top)
    $FileType = _FileListToArray(@ScriptDir&"\"&$Folders[$i], "*", 1)
    if $FileType[0]>0 Then
    If StringRight($FileType[1], 3) = "txt" Then
    $file = FileOpen(@ScriptDir&"\"&$Folders[$i]&"\"&$FileType[1], 0)
    $FileText = FileRead($file)
    $Input = GUICtrlCreateEdit($FileText, 150, $top , 350, 20)
    FileClose($file)
    ElseIf StringRight($FileType[1], 3) = "exe" Then
    $Exen[$i] = $FileType[1]
    If $i < 10 Then
    $null = '0'
    Else
    $null = ''
    EndIf
    Assign ( "Button" & $null & $i, GUICtrlCreateButton("KeyGen", 150, $top, 50, 20), 2 )
    EndIf
    Else
    $Label = GuiCtrlCreateLabel("Andere", 150, $top)
    EndIf
    $top = $top + 25
    Next

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

    GUISetState(@SW_SHOW)

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

    While 1
    $msg = GuiGetMsg()

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

    For $r = 1 To $ButtonAnz Step 1

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

    If $r < 10 Then
    $null = '0'
    Else
    $null = ''
    EndIf

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

    If IsDeclared("Button" & $null & $r) Then
    If $msg = Eval("Button" & $null & $r) Then
    Run(@ScriptDir&"\"&$Folders[$r]&"\"&$Exen[$r])
    EndIf
    EndIf
    Next

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

    Select
    Case $msg = $GUI_EVENT_CLOSE
    ExitLoop
    Case $msg = $closebutton
    ExitLoop
    EndSelect
    WEnd
    Exit

    [/autoit]