#include <GuiTreeView.au3> #include<WindowsConstants.au3> #include<GuiConstantsEx.au3> #include <File.au3> Global $sFilePath $hGUI = GUICreate("",340,470 ) $hTreeView = GUICtrlCreateTreeView (10, 10, 320, 400 , -1 , $WS_EX_CLIENTEDGE+$TVS_SINGLEEXPAND) _GUICtrlTreeView_SetBkColor ($hTreeView , 0xC0C0C0 ) GUICtrlSetFont ($hTreeView , 8.25 , 204 , 0 , "MS Shell Dlg") _GUICtrlTreeView_SetTextColor ($hTreeView , 0x541414 ) $btOK= GUICtrlCreateButton("OK", 270, 430, 60, 30) GUIRegisterMsg( $WM_NOTIFY , "WM_NOTIFY" ) GUISetState () _DrivesTreeView($hTreeView) While 1 Local $TagString_HEX $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btOK ConsoleWrite($sFilePath & @LF) EndSwitch WEnd ;=============================================== Func _DrivesTreeView($hTV, $sType= "FIXED") ;=============================================== $aDisk=DriveGetDrive($sType) For $i=1 To UBound($aDisk)-1 $aDisk[$i]=StringUpper ( $aDisk[$i] ) $hItem= GUICtrlCreateTreeViewItem($aDisk[$i], $hTV) _GUICtrlTreeView_SetIcon($hTV,$hItem, "shell32.dll",7) Next EndFunc ;============================================== Func _ClickItemTV($hTV,$hItem=-1) ;============================================== If $hItem=0 Then Return 0 $sFullName=StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $hItem) ,'|','\') If _GUICtrlTreeView_GetChildren($hTV, $hItem) = False Then If Not StringInStr(FileGetAttrib ( $sFullName ),"D")Then Return $sFullName $aFolderList = _FileListToArray($sFullName, '*', 2) For $i = 1 To UBound($aFolderList) - 1 $hChild= _GUICtrlTreeView_AddChild($hTV,$hItem, $aFolderList[$i],0) _GUICtrlTreeView_SetIcon($hTV,$hChild, "shell32.dll",3) Next _GUICtrlTreeView_Expand($hTV, $hItem) EndIf Return $sFullName EndFunc ; ====> ClickItemTV ;================================================================== Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ;================================================================== #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView,$hWndListView $hWndTreeView = $hTreeView If Not IsHWnd($hTreeView) Then $hWndTreeView = GUICtrlGetHandle($hTreeView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $NM_CLICK Local $tPOINT = DllStructCreate("int X;int Y") DllStructSetData($tPOINT, "X", MouseGetPos(0)) DllStructSetData($tPOINT, "Y", MouseGetPos(1)) DllCall("user32.dll", "int", "ScreenToClient", _ "hwnd", $hWndTreeview, _ "ptr", DllStructGetPtr($tPOINT)) Local $iX = DllStructGetData($tPOINT, "X") Local $iY = DllStructGetData($tPOINT, "Y") $hClickedItemTV = _GUICtrlTreeView_HitTestItem($hWndTreeview, $iX, $iY) $sFilePath=_ClickItemTV($hWndTreeview, $hClickedItemTV) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ; ===> WM_NOTIFY |