1

请帮助我如何创建一个列表,可能来自一个arrayList。输入框是文件夹的来源,它的所有png文件都会在数组列表中,并显示在GU中。谢谢

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Array.au3>

;GUI
GUICreate("Automation", 300, 500)
$sourceFolder = GUICtrlCreateInput ("Source Folder" , 10, 10,280, 20 )
$add = GUICtrlCreateButton("Add", 10, 35, 75, 20)
$mylist = GUICtrlCreateList("", 10, 60, 280, 300)

$sourceFolder = ControlGetText("Automation", "", "Edit1")
Local $FileList = _FileListToArray($sourceFolder, "*.png")


    $msg = 0
    While $msg 
        $msg = GUIGetMsg()
        Select
            Case $msg = $add
                GUICtrlSetData($mylist,$FileList)
                Exit
        EndSelect
    WEnd

If $sourceFolder > 1 Then
   If @error = 1 Then
       MsgBox(0, "", "No Folders Found.")
       Exit
   EndIf
   If @error = 4 Then
       MsgBox(0, "", "No Files Found.")
       Exit
   EndIf
   $arrayFileList = _ArrayDisplay($FileList)
EndIf



; GUI MESSAGE LOOP
GUISetState(@SW_SHOW)
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
4

1 回答 1

2

你的代码有很多问题。

  • 2个消息循环是非常糟糕的做法
  • 第一个消息循环永远不会开始,因为您有While $msg, 并设置$msg0之前的行。
  • 您在第一个消息循环之前读取源文件夹控件,因此它的值将始终是"Source Folder"而不是您想要的目录。
  • 即使第一个消息循环确实运行了,GUI 也不会显示。

就你想要做的事情而言:它只是一个 For...Next 对返回数组的循环。

#include <GuiConstantsEx.au3>
#include <File.au3>
#include <Array.au3>

;GUI
GUICreate("Automation", 300, 500)
$sourceFolder = GUICtrlCreateInput("Source Folder", 10, 10, 280, 20)
$add = GUICtrlCreateButton("Add", 10, 35, 75, 20)
$mylist = GUICtrlCreateList("", 10, 60, 280, 300)


GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $add
            $sFolder = ControlGetText("Automation", "", "Edit1")
            Local $FileList = _FileListToArray($sFolder, "*.*")

            If @error = 1 Then
                MsgBox(0, "", "No Folders Found.")
                Exit
            EndIf
            If @error = 4 Then
                MsgBox(0, "", "No Files Found.")
                Exit
            EndIf

            For $i = 1 To $FileList[0]
                GUICtrlSetData($mylist, $FileList[$i])
            Next
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd
于 2013-06-19T07:05:34.633 回答