[已解决]想显示文件夹中文件在listview中,下面代码应怎样修改?
本帖最后由 oceanwind 于 2013-5-18 23:03 编辑#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <SendMessage.au3>
#include <Array.au3>
#include <file.au3>
#include <Math.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
GUICreate("test", 220, 250, 100, 200)
Local $selected_file_foler = @ScriptDir & "\people_num",$msg
$image_file_listview = GUICtrlCreateListView("image file",10, 10, 200, 150)
GUISetState(@SW_SHOW )
_set_image_list($selected_file_foler)
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd
Func _set_image_list($passed_file_folder)
Local $jpg_file_array,$si
$jpg_file_array = _FileListToArray($passed_file_folder, "*.jpg", 1)
_GUICtrlListView_DeleteAllItems($image_file_listview)
For $i = 1 To $jpg_file_array
;MsgBox(0,"",$jpg_file_array)
GUICtrlCreateListViewItem ( $jpg_file_array[$si] , $image_file_listview)
Next
EndFunc #include <file.au3>
#include <GuiListView.au3>
$form = GUICreate("test", 220, 250, 100, 200)
Local $msg
$image_file_listview = GUICtrlCreateListView("image file", 10, 10, 200, 150)
$list = GUICtrlGetHandle(-1)
$bt = GUICtrlCreateButton('选择文件夹', 70, 200, 85, 28)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
Case $bt
_set_image_list()
EndSwitch
WEnd
Func _set_image_list()
Local $folder = FileSelectFolder('请选择一个目录', '', 1 + 2 + 4, @ScriptDir, $form)
If @error Then Return
_GUICtrlListView_DeleteAllItems($list)
Local $jpg_file_array = _FileListToArray($folder, "*.jpg", 1)
If IsArray($jpg_file_array) Then
_GUICtrlListView_BeginUpdate($list)
For $i = 1 To $jpg_file_array
_GUICtrlListView_AddItem($list, $jpg_file_array[$i])
Next
_GUICtrlListView_EndUpdate($list)
EndIf
EndFunc
user3000 发表于 2013-5-18 21:28 http://www.autoitx.com/images/common/back.gif
谢谢,这样可以
但是我就是不想手动选择文件夹。
另外为啥用循环加入就不行,但是用
GUICtrlCreateListViewItem ( $jpg_file_array , $image_file_listview)
一个一个添加又可以,是啥原因呢? 回复 2# user3000
我原码换成你用的函数_GUICtrlListView_AddItem($image_file_listview, $jpg_file_array[$i])
后成功了
谢谢
页:
[1]