#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include<file.au3>
#include<array.au3>
#include <GuiListView.au3>
Local $Drivelist
HotKeySet("{F1}", "build")
;HotKeySet("{enter}", "search")
$Form1 = GUICreate("索引", 627, 531, 79, 247)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$Group1 = GUICtrlCreateGroup("", 8, 8, 609, 113)
$Pic1 = GUICtrlCreatePic("1.jpg", 424, 24, 177, 81)
$Label1 = GUICtrlCreateLabel("关键字", 24, 27, 36, 17)
$Label2 = GUICtrlCreateLabel("扩展名", 24, 59, 36, 17)
$Label3 = GUICtrlCreateLabel("---------------------------------", 24, 86, 236, 17)
$Label4 = GUICtrlCreateLabel("F1:更新数据库" & "", 14, 510, 500, 17)
$Label5 = GUICtrlCreateLabel("搜索耗时:" & "", 350, 510, 200, 17)
$Combo2 = GUICtrlCreateCombo("", 64, 56, 337, 25)
GUICtrlSetData(-1, "dll|exe|ico|txt|jpg|bmp|", "")
$Combo1 = GUICtrlCreateCombo("", 64, 24, 337, 25)
$ListView1 = GUICtrlCreateListView("", 8, 136, 609, 361)
_GUICtrlListView_AddColumn($ListView1, "No.", 40)
_GUICtrlListView_AddColumn($ListView1, "路径", 540)
GUISetState(@SW_SHOW)
GUICtrlSetState($Combo1, $GUI_FOCUS)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func build()
$Folder = FileSelectFolder("选择数据库目标分区或文件夹", "")
If $Folder <> '' Then
$start = TimerInit()
GUICtrlSetData($Label4, "F1:更新中...")
$a = _FileSearchToArray($Folder, "*.*", 1)
$end = TimerDiff($start)
GUICtrlSetData($Label4, "F1:更新完毕,耗时:" & StringLeft($end,8)&'毫秒')
;_ArrayDisplay($a)
Else
EndIf
EndFunc ;==>build
Func search()
GUICtrlSetData($Label4, "F1:更新数据库")
$n = 1
$start = TimerInit()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
Dim $aRecords
If Not _FileReadToArray("filelist.data", $aRecords) Then
MsgBox(4096, "Error", "读取索引数据失败error:" & @error)
Exit
EndIf
For $x = 1 To $aRecords[0]
If StringInStr($aRecords[$x], GUICtrlRead($Combo1), 2) And StringRight($aRecords[$x], StringLen(GUICtrlRead($Combo2))) = GUICtrlRead($Combo2) Then
_GUICtrlListView_AddItem($ListView1, $n, 0)
_GUICtrlListView_AddSubItem($ListView1, $n - 1, $aRecords[$x], 1, 1)
$n += 1
EndIf
Next
$end = TimerDiff($start)
GUICtrlSetData($Label5, "搜索完毕,耗时:" & StringLeft($end,8)&'毫秒')
EndFunc ;==>search
Func _FilesearchToArray($sPath, $sFilter = "*", $sSub = 0, $sFalg = 0, $sOUT = "")
$sSize = 0
If $sOUT = "" Then $sOUT = @ScriptDir & "\filelist.data"
If StringRight($sPath, 1) <> "" Then $sPath = $sPath & ""
If $sSub = 1 Then
$sSub = " /s"
Else
$sSub = ""
EndIf
If $sFilter = "" Then $sFilter = "*"
Select
Case $sFalg = 1
$sFalg = "/a:d"
Case $sFalg = 2
$sFalg = "/a:-d"
Case $sFalg = 3
$sFalg = "/a:d"
$sSize = 1
Case Else
$sFalg = "/a"
EndSelect
RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & $sFilter & '" ' & $sFalg & ' /b' & $sSub & ' > "' & $sOUT & '"', '', @SW_HIDE)
Dim $sfilelist
_FileReadToArray($sOUT, $sfilelist)
If Not IsArray($sfilelist) Then
Dim $sfilelist[1]
$sfilelist[0] = 0
Else
If $sfilelist[$sfilelist[0]] = "" Then
_ArrayDelete($sfilelist, $sfilelist[0])
$sfilelist[0] = $sfilelist[0] - 1
EndIf
EndIf
If $sSub = "" Then
For $x = 1 To $sfilelist[0]
$sfilelist[$x] = $sPath & $sfilelist[$x]
Next
EndIf
If $sSize = 1 Then
For $x = 1 To $sfilelist[0]
$sfilelist[$x] = $sfilelist[$x] & ":size:" & DirGetSize($sfilelist[$x])
Next
EndIf
Return $sfilelist
EndFunc ;==>_FilesearchToArray
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
;~ ...
Case $NM_DBLCLK ; 双击
$Index = _GUICtrlListView_GetSelectedIndices($ListView1)
If Not StringLen($Index) Then
MsgBox(0, "", "未选定")
Return
EndIf
;MsgBox(0, '你选择了文件', _GUICtrlListView_GetItemText($ListView1, Number($Index), 1))
ShellExecute( _GUICtrlListView_GetItemText($ListView1, Number($Index), 1))
Case $NM_RCLICK ; 右击
;~ ...
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo
If Not IsHWnd($Combo1) Then $hWndCombo = GUICtrlGetHandle($Combo1)
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF)
$iCode = BitShift($iwParam, 16)
Switch $hWndFrom
Case $Combo1, $hWndCombo
Switch $iCode
Case $CBN_EDITUPDATE
Sleep(500)
search()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND