本帖最后由 C.L 于 2010-5-24 01:16 编辑
今天有空看看这个问题,觉得不能同时选中文件夹和文件,还真是个问题
所以有空写了个GUI,可以同时选中文件夹和文件,方便以后可以使用,只是列表内的图标只有两种,只区分文件和文件夹,图标我懒得去搞了,好象论坛内也有专门的代码讨论图标显示的问题(补充一下,以下代码是在win7下做的,不知道和XP里的图标是否一样)
把这个代码发在这里,起个抛砖引玉的作用。
废话少说了,上代码:#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
;~ #include <array.au3>
#include <file.au3>
$Form1 = GUICreate("test", 400, 380, @DesktopWidth / 2 - 100, @DesktopHeight / 2 - 100)
$aStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)
$listview1 = GUICtrlCreateListView("名称", 0, 0, 398, 290, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
_GUICtrlListView_SetExtendedListViewStyle($listview1, $aStyles)
_GUICtrlListView_SetView($listview1, "1")
GUICtrlSetBkColor($listview1, 0xffffff)
$button1 = GUICtrlCreateButton ("选定目标",200,330,100,30)
GUISetState(@SW_SHOW)
$curdir = FileSelectFolder ("选择目录","")
If StringRight ($curdir,1) <> "" Then $curdir &= ""
$folder = _FileListToArray($curdir, "*", 0)
If IsArray($folder) Then
For $i=0 To $folder[0]
$listteam = GUICtrlCreateListViewItem ($folder[$i],$listview1)
$attrib = FileGetAttrib ($curdir&$folder[$i])
If StringInStr($attrib, "D") Then
GUICtrlSetImage($listteam, "shell32.dll", 5)
Else
GUICtrlSetImage($listteam, "shell32.dll", 1)
EndIf
Next
WinSetTitle ("test","","test " & $curdir)
EndIf
While 1
$nMsg = GUIGetMsg ()
Switch $nMsg
Case -3
Exit
Case $button1
$totalnum = _GUICtrlListView_GetItemCount($listview1)
$selectcount = _GUICtrlListView_GetSelectedCount($listview1)
$out = ""
For $i = 0 To $totalnum-1
If $selectcount Then
If _GUICtrlListView_GetItemSelected($listview1, $i) == True Then
$val = _GUICtrlListView_GetItemTextString($listview1, $i)
$attrib = FileGetAttrib ($curdir&$val)
If StringInStr($attrib, "D") Then
$out &= $val&" 是目录"&@CRLF
Else
$out &= $val&" 是文件" & @CRLF
EndIf
EndIf
Else
$out = "没有选择文件"
EndIf
Next
MsgBox (0,"已选择的文件","当前的目录:"&$curdir & @CRLF & $out)
EndSwitch
WEnd
|