#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
Opt('GUIOnEventMode', 1)
Global $aCtrlRange[2]
$gui = GUICreate('磁盘信息管理', 500, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
$cm_Main = GUICtrlCreateContextMenu(-1)
GUICtrlCreateMenuItem('&Refresh', $cm_Main)
GUICtrlSetOnEvent(-1, '_Refresh')
$pg_Used = GUICtrlCreateProgress(0, 180, 380, 20, $PBS_SMOOTH)
GUICtrlSetColor(-1, 0xff)
$lb_UsedSh = GUICtrlCreateLabel('', 1, 181, 380, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0)
$lb_Used = GUICtrlCreateLabel('', 0, 180, 380, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetColor(-1, 0xffffff)
GUICtrlCreateButton('打 开', 380, 180, 60, 20)
GUICtrlSetOnEvent(-1, '_Explore')
GUICtrlCreateButton('刷 新', 440, 180, 60, 20)
GUICtrlSetOnEvent(-1, '_Refresh')
$lv_Drives = GUICtrlCreateListView('盘符|卷标|类型|状态|文件系统|磁盘编号|可用空间|已使用空间|磁盘容量', 0, 0, 500, 180)
Opt('GUIDataSeparatorChar', @LF)
GUISetState()
$aCtrlRange = _ListView()
$iLvSel = 0
$iLvSelMem = -1
While 1
$iLvSel = _GUICtrlListView_GetNextItem($lv_Drives)
If $iLvSel <> -1 And $iLvSel <> $iLvSelMem Then
$sUsedSpace = _GUICtrlListView_GetItemText($lv_Drives, $iLvSel, 7)
$sUsedSpace = StringRegExpReplace($sUsedSpace, '.*\((\d+)%\)', '\1')
If Not @error And @extended Then
GUICtrlSetData($pg_Used, $sUsedSpace)
GUICtrlSetData($lb_Used, 'Used space (' & $sUsedSpace & '%)')
GUICtrlSetData($lb_UsedSh, 'Used space (' & $sUsedSpace & '%)')
Else
GUICtrlSetData($pg_Used, 0)
GUICtrlSetData($lb_Used, '')
GUICtrlSetData($lb_UsedSh, '')
EndIf
$iLvSelMem = $iLvSel
EndIf
Sleep(10)
WEnd
Func _Exit()
GUIDelete($gui)
Exit
EndFunc
Func _Refresh()
For $iCtrl = $aCtrlRange[0] To $aCtrlRange[1]
GUICtrlDelete($iCtrl)
Next
Global $aCtrlRange = _ListView()
EndFunc
Func _Explore()
$iLvSel = _GUICtrlListView_GetNextItem($lv_Drives)
If $iLvSel <> -1 Then
$sDrive = _GUICtrlListView_GetItemText($lv_Drives, $iLvSel, 0)
ShellExecute($sDrive)
EndIf
EndFunc
Func _ListView()
Local $aCtrlRange[2]
$aCtrlRange[0] = GUICtrlCreateDummy()
$aDrives = DriveGetDrive('all')
For $i = 1 To $aDrives[0]
$sDrive = StringUpper($aDrives[$i])
$iTotalSpace = DriveSpaceTotal($sDrive)
If $iTotalSpace <= 0 Then
$sFreeSpace = '-'
$sUsedSpace = '-'
$sTotalSpace = '-'
Else
$sTotalByteAmt = 'MB'
$sFreeByteAmt = 'MB'
$sUsedByteAmt = 'MB'
$iFreeSpace = DriveSpaceFree($sDrive)
$iUsedSpace = $iTotalSpace - $iFreeSpace
$iFreePercent = 0
$iUsedPercent = 0
If $iTotalSpace > 0 Then
$iFreePercent = Round($iFreeSpace / $iTotalSpace * 100)
$iUsedPercent = 100 - $iFreePercent
EndIf
If $iTotalSpace > 1024 Then
$iTotalSpace /= 1024
$sTotalByteAmt = 'GB'
EndIf
If $iFreeSpace > 1024 Then
$iFreeSpace /= 1024
$sFreeByteAmt = 'GB'
EndIf
If $iUsedSpace > 1024 Then
$iUsedSpace /= 1024
$sUsedByteAmt = 'GB'
EndIf
$sTotalSpace = StringFormat('%.2f %s', $iTotalSpace, $sTotalByteAmt)
$sFreeSpace = StringFormat('%.2f %s (%d%%)', $iFreeSpace, $sFreeByteAmt, $iFreePercent)
$sUsedSpace = StringFormat('%.2f %s (%d%%)', $iUsedSpace, $sUsedByteAmt, $iUsedPercent)
EndIf
$sLabel = DriveGetLabel($sDrive)
If $sLabel = '' Then $sLabel = '[None]'
GUICtrlCreateListViewItem( _
StringFormat('%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s', _
$sDrive, _
$sLabel, _
DriveGetType($sDrive), _
DriveStatus($sDrive), _
DriveGetFileSystem($sDrive), _
DriveGetSerial($sDrive), _
$sFreeSpace, _
$sUsedSpace, _
$sTotalSpace), _
$lv_Drives)
Next
$aCtrlRange[1] = GUICtrlCreateDummy()
Return $aCtrlRange
EndFunc
|