[mw_shl_code=actionscript3,true]#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPIFiles.au3>
$S_Form = GUICreate("请选择目录", 250, 210, 345, 166)
$Tvw1 = GUICtrlCreateTreeView(8, 8, 233, 160,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
$S_CmdOK = GUICtrlCreateButton("选择", 112, 175, 57, 25, $BS_DEFPUSHBUTTON)
$S_CmdClose = GUICtrlCreateButton("关闭", 176, 175, 57, 25)
GUISetState(@SW_SHOW)
_AddTreeView()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE,$S_CmdClose
Exit
Case $S_CmdOK
MsgBox(0,0,GUICtrlRead($Tvw1,1))
EndSwitch
WEnd
Func _AddTreeView()
Local $DriveList,$i
$t_Title = GUICtrlCreateTreeViewItem('本地磁盘', $Tvw1)
GUICtrlSetColor(-1, 0x0000C0)
$DriveList = StringSplit(_GetLogicalDrives(),',')
For $i = 1 To $DriveList[0]
GUICtrlCreateTreeViewItem($DriveList[$i] & ':\', $t_Title)
Next
GUICtrlSetState($t_Title, BitOR($GUI_EXPAND, $GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold
EndFunc ;==>_AddTreeView
;摘自DriveGetDrive示例
Func _GetLogicalDrives()
Local $aData, $aDrive = DriveGetDrive('FIXED')
Local $aList[10]
Local $Return
For $i = 0 To UBound($aDrive) - 1
$aList[$i] = ''
Next
If IsArray($aDrive) Then
For $i = 1 To $aDrive[0]
$aData = _WinAPI_GetDriveNumber($aDrive[$i])
If IsArray($aData) Then
$aList[$aData[1]] &= StringUpper($aDrive[$i]) & ' '
EndIf
Next
EndIf
For $i = 0 To UBound($aDrive) - 1
If $aList[$i] Then
;~ ConsoleWrite('Drive' & $i & ' => ' & $aList[$i] & @CRLF)
$Return &= StringReplace($aList[$i], ': ', ',')
EndIf
Next
$Return = StringLeft($Return, StringLen($Return) - 1)
Return $Return
EndFunc ;==>_GetLogicalDrives[/mw_shl_code] |