#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
;Opt("TrayMenuMode", 3)
Global $g_Form1 = GUICreate("Form1", 615, 477, -1, -1)
Global $g_Label1 = GUICtrlCreateLabel("地址:", 16, 16, 40, 17)
Global $g_Label2 = GUICtrlCreateLabel("文件名:", 16, 48, 52, 17)
Global $g_Input_Path = GUICtrlCreateInput("", 64, 16, 297, 21)
Global $g_Button_Path = GUICtrlCreateButton("...", 376, 16, 49, 25)
Global $g_Input_Search = GUICtrlCreateInput("", 64, 48, 297, 21)
Global $g_Button_Search = GUICtrlCreateButton("搜索", 376, 48, 49, 25)
Global $g_TreeView_ID = GUICtrlCreateTreeView(16, 80, 201, 321, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT), $WS_EX_CLIENTEDGE)
Global $g_TreeView_hWnd = GUICtrlGetHandle($g_TreeView_ID)
Global $g_ListView_ID = GUICtrlCreateListView("文件|目录", 240, 80, 337, 329, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES))
Global $g_ListView_hWnd = GUICtrlGetHandle($g_ListView_ID)
_GUICtrlListView_SetColumnWidth($g_ListView_ID, 0, $LVSCW_AUTOSIZE_USEHEADER)
Global $g_Button_Open = GUICtrlCreateButton("打开", 16, 432, 81, 33)
Global $g_Button_Exit = GUICtrlCreateButton("退出", 112, 432, 81, 33)
Global $g_Button5 = GUICtrlCreateButton("关于", 496, 432, 81, 33)
Global $Path
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()
While 1
Local $msg = GUIGetMsg()
Switch $msg
Case $g_Button_Exit, -3
Exit
Case $g_Button_Path
Local $hPath = FileSelectFolder("选择文件夹.", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 7)
If @error Then ContinueLoop
;$Path = $hPath & ""
$Path = $hPath
_GUICtrlTreeView_DeleteAll($g_TreeView_hWnd)
_GUICtrlTreeView_BeginUpdate($g_TreeView_hWnd)
_AddPath($Path, $g_TreeView_ID)
_GUICtrlTreeView_EndUpdate($g_TreeView_hWnd)
GUICtrlSetData($g_Input_Path, $Path)
_AddFile($Path)
Case $g_Button_Search
Local $SearchFile = GUICtrlRead($g_Input_Search)
If @error Or $SearchFile = "" Then ContinueLoop
Local $PID = Run('"' & @ComSpec & '" /c dir /s /a:-d /b "' & $Path & '\*' & $SearchFile & '*"', '', @SW_HIDE, 6), $STDOUT
ProcessWaitClose($PID)
$STDOUT = StdoutRead($PID)
_GUICtrlListView_BeginUpdate($g_ListView_hWnd)
_GUICtrlListView_DeleteAllItems($g_ListView_hWnd)
;Local $Match = StringRegExp(StringRegExpReplace($STDOUT, '(.+)\\([^\r]+)', '$2\|$1'), "[^\r\n]+", 3)
;For $FILE In $Match
; GUICtrlCreateListViewItem($FILE, $g_ListView_ID)
;Next
Local $aMatch = StringRegExp($STDOUT, '(.+)\\([^\r]+)', 3)
If @error Then ContinueLoop
For $i = 0 To UBound($aMatch) - 1 Step 2
Local $sText = ''
If StringRegExp($aMatch[$i], '^[a-zA-Z]) Then
$sText = $aMatch[$i + 1] & '|' & $aMatch[$i] & ':\'
Else
$sText = $aMatch[$i + 1] & '|' & $aMatch[$i]
EndIf
GUICtrlCreateListViewItem($sText, $g_ListView_ID)
Next
_GUICtrlListView_SetColumnWidth($g_ListView_hWnd, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_EndUpdate($g_ListView_hWnd)
Case $g_Button_Open
ShellExecute(StringRegExpReplace(GUICtrlRead(GUICtrlRead($g_ListView_ID)), '^([^\|]+)\|([^\|]+)\|', '$2\\$1'))
EndSwitch
Sleep(10)
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam)
Local $tNMHDR, $hwndFrom, $code
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$code = DllStructGetData($tNMHDR, "Code")
Switch $code
Case $NM_DBLCLK
If DllStructGetData($tNMHDR, "hWndFrom") == $g_ListView_hWnd Then ShellExecute(StringRegExpReplace(GUICtrlRead(GUICtrlRead($g_ListView_ID)), '^([^\|]+)\|([^\|]+)\|', '$2\\$1'))
Case $TVN_SELCHANGINGW
$pTV = DllStructCreate($tagNMTREEVIEW, $lParam);_DebugPrint("$TVN_SELCHANGING")
Local $hItem = DllStructGetData($pTV, 'NewhItem')
If Not $hItem Then Return 0
Local $hParent = _GUICtrlTreeView_GetParentHandle($g_TreeView_hWnd, $hItem)
Local $hPath = _GUICtrlTreeView_GetText($g_TreeView_hWnd, $hItem)
While $hParent
$hPath = _GUICtrlTreeView_GetText($g_TreeView_hWnd, $hParent) & "" & $hPath
$hParent = _GUICtrlTreeView_GetParentHandle($g_TreeView_hWnd, $hParent)
WEnd
_AddFile($Path & $hPath)
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _AddFile($Dir)
Local $hSearch = FileFindFirstFile($Dir & "\*")
If @error Then Return 0
_GUICtrlListView_DeleteAllItems($g_ListView_hWnd)
_GUICtrlListView_BeginUpdate($g_ListView_hWnd)
While 1
Local $sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
If Not @extended Then
GUICtrlCreateListViewItem($sFile & "|" & $Dir, $g_ListView_ID)
EndIf
WEnd
_GUICtrlListView_EndUpdate($g_ListView_hWnd)
_GUICtrlListView_SetColumnWidth($g_ListView_hWnd, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($g_ListView_hWnd, 1, $LVSCW_AUTOSIZE)
_GUICtrlListView_SetColumnWidth($g_ListView_hWnd, 1, $LVSCW_AUTOSIZE_USEHEADER)
FileClose($hSearch)
EndFunc ;==>_AddFile
Func _AddPath($Dir, $ParentID)
Local $hSearch = FileFindFirstFile($Dir & "\*")
If $hSearch = -1 Then Return 0
While 1
Local $sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
If @extended Then
Local $hItem = GUICtrlCreateTreeViewItem($sFile, $ParentID)
_AddPath($Dir & "" & $sFile, $hItem)
ContinueLoop
EndIf
WEnd
FileClose($hSearch)
EndFunc ;==>_AddPath