#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=autorun.ico
#AutoIt3Wrapper_outfile=文件搜索列表.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=Winter.Cao@Live.cn
#AutoIt3Wrapper_Res_Description=Flie Search List Prog
#AutoIt3Wrapper_Res_Fileversion=0.0.1.0
#AutoIt3Wrapper_Res_LegalCopyright=Copyright (C) 1998-2009 Caodongchun
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseAnsi=y
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
TraySetClick(16)
$Filelist = _FileListToArray(@ScriptDir, '*', 1)
$JForm = GUICreate('文件搜索', 800, 600)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked1");退出OnEvent
GUICtrlCreateLabel('请填写关键字', 10, 13, 75, 20)
$JInput = GUICtrlCreateCombo('', 85, 10, 655, 20)
GUICtrlSetOnEvent(-1, '_Click');OnEvent
$JSearchButton = GUICtrlCreateButton('搜索', 750, 10, 40, 20)
GUICtrlSetOnEvent(-1, '_Click');OnEvent
$JList = GUICtrlCreateListView(' 文件名 |文件类型', 10, 40, 780, 550)
_GUICtrlListView_SetExtendedListViewStyle($JList, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetColumnWidth($JList, 0, 700)
_GUICtrlListView_SetColumnWidth($JList, 1, 70)
$EXIT = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, '_Exit')
TraySetOnEvent(-8, '_show')
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW, $JForm)
AdlibRegister('_Enter', 150)
Func _Enter()
If ControlGetFocus($JForm) = 'Edit1' And _IsPressed("0D") Then
_GetFileName(GUICtrlRead($JInput))
EndIf
EndFunc ;==>_Enter
Func _Exit()
Exit
EndFunc ;==>_Exit
Func _Click()
If @GUI_CtrlId = $JSearchButton Then _GetFileName(GUICtrlRead($JInput))
EndFunc ;==>_Click
Func _GetFileName($sString = '')
_GUICtrlListView_DeleteAllItems($JList)
$WArray = StringSplit(GUICtrlRead($JInput), ' ')
For $x = 1 To $Filelist[0]
$Flag = 0
For $y = 1 To $WArray[0]
If StringInStr($Filelist[$x], $WArray[$y]) <> 0 Then $Flag += 1;
Next
If $Flag = $WArray[0] Then
$Filename = StringRegExp($Filelist[$x], '(.*)\.[^\.]*', 1)
If IsArray($Filename) Then
$Filename = $Filename[0]
Else
$Filename = $Filelist[$x]
EndIf
$Filetype = StringRegExp($Filelist[$x], '.*(\.[^\.]*)', 1)
If IsArray($Filetype) Then
$Filetype = $Filetype[0]
Else
$Filetype = ''
EndIf
GUICtrlCreateListViewItem($Filename & '|' & $Filetype, $JList)
EndIf
Next
EndFunc ;==>_GetFileName
Func CLOSEClicked1()
GUISetState(@SW_HIDE)
EndFunc ;==>CLOSEClicked1
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tInfo, $hWndListView = $JList
If Not IsHWnd($JList) Then $hWndListView = GUICtrlGetHandle($JList)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK; Sent by a list-view control when the user double-clicks an item with the left mouse button
$SelFileN = _GUICtrlListView_GetItemText($JList, Int(_GUICtrlListView_GetSelectedIndices($JList)))
$SelFileT = _GUICtrlListView_GetItemText($JList, Int(_GUICtrlListView_GetSelectedIndices($JList)), 1)
ShellExecute(@ScriptDir & '\' & $SelFileN & $SelFileT)
Case $NM_RCLICK
ShellExecute(@ScriptDir & '\')
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _show()
GUISetState(@SW_SHOW)
EndFunc ;==>_show
Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
Local $hSearch, $sFile, $sFileList, $sDelim = "|"
$sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "" ; ensure single trailing backslash
If Not FileExists($sPath) Then Return SetError(1, 1, "")
If StringRegExp($sFilter, "[\\/:><\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
$hSearch = FileFindFirstFile($sPath & $sFilter)
If @error Then Return SetError(4, 4, "")
While 1
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
If ($iFlag + @extended = 2) Then ContinueLoop
$sFileList &= $sDelim & $sFile
WEnd
FileClose($hSearch)
If Not $sFileList Then Return SetError(4, 4, "")
Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc ;==>_FileListToArray
Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
; $hexKey must be the value of one of the keys.
; _Is_Key_Pressed will return 0 if the key is not pressed, 1 if it is.
Local $a_R = DllCall($vDLL, "short", "GetAsyncKeyState", "int", '0x' & $sHexKey)
If @error Then Return SetError(@error, @extended, False)
Return BitAND($a_R[0], 0x8000) <> 0
EndFunc ;==>_IsPressed
While 1
Sleep(100)
WEnd