回复 2# user3000
#include <GUIListBox.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\Administrator\Desktop\Form1.kxf
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Input1 = GUICtrlCreateInput("", 64, 40, 337, 21)
$Button1 = GUICtrlCreateButton("...", 408, 40, 43, 21)
$Button2 = GUICtrlCreateButton("test", 488, 40, 75, 21)
$Button3 = GUICtrlCreateButton("返回", 488, 65, 75, 21)
$Progress1 = GUICtrlCreateProgress(64, 72, 390, 17)
$List1 = GUICtrlCreateList("", 64, 104, 550, 321)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
GUICtrlSetData($Input1,FileSelectFolder("选择一个文件夹",""))
Case $Button2
If StringMid(GUICtrlRead($Input1),2,2) <> ":\" Then
MsgBox(0,"提示","路径错误。")
Else
GUICtrlSetData($List1,"")
callback(GUICtrlRead($Input1))
_GUICtrlListBox_SetSel($List1,1) ;为什么这样不能让Listbox默认选择第一条
EndIf
Case $Button3
MsgBox(0,"",_GUICtrlListBox_GetCount($List1))
EndSwitch
WEnd
;搜索指定目录下的所有文件与文件夹,不包括子目录
Func callback($path)
Local $HWND = FileFindFirstFile($path & "\*.*")
If $HWND = -1 Then Exit
While 1
Local $sFile = FileFindNextFile($HWND)
If @error Then ExitLoop
GUICtrlSetData($List1,$path & "\" & $sFile)
WEnd
EndFunc
为什么这样不能让 Listbox 选择第一条 |