#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) Global $hListView, $hButton CreateGUI() Func CreateGUI() Local $iExWindowStyle = BitOR($WS_EX_DLGMODALFRAME, $WS_EX_CLIENTEDGE) Local $iExListViewStyle = BitOR($LVS_EX_SUBITEMIMAGES, $LVS_EX_GRIDLINES) GUICreate("Безопасное извлечение устройства", 470, 250) $hListView = GUICtrlCreateListView("Имя|Тип|Полный объем|Свободно|Файловая система", 10, 10, 450, 180, -1, $iExWindowStyle) _GUICtrlListView_SetExtendedListViewStyle($hListView, $iExListViewStyle) $hButton = GUICtrlCreateButton("Остановить", 10, 200) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetState() local $hImage = _GUIImageList_Create(16, 16, 5, 3) _GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -8) _GUICtrlListView_SetImageList($hListView, $hImage, 1) local $tblDrives = DriveGetDrive("REMOVABLE") ; таблица съемных устройств If Not @error Then For $i = 1 To $tblDrives[0] if ($tblDrives[$i] <> "a:") then ; исключаем флоппик local $strLabel = DriveGetLabel($tblDrives[$i]) if ($strLabel == "") then ; если метка отсутствует $strLabel = "Съемный диск" endif local $nSpaceTotal = DriveSpaceTotal($tblDrives[$i]) local $nSpaceFree = DriveSpaceFree($tblDrives[$i]) local $strFS = DriveGetFileSystem($tblDrives[$i]) local $nItem = _GUICtrlListView_AddItem($hListView, "(" & StringUpper($tblDrives[$i]) & ") " & $strLabel, 0) _GUICtrlListView_SetItemParam($hListView, $nItem, $tblDrives[$i]) _GUICtrlListView_AddSubItem($hListView, $nItem, "Съемный диск", 1) _GUICtrlListView_AddSubItem($hListView, $nItem, String_GetFormattedSize($nSpaceTotal*1024^2), 2) _GUICtrlListView_AddSubItem($hListView, $nItem, String_GetFormattedSize($nSpaceFree*1024^2), 3) _GUICtrlListView_AddSubItem($hListView, $nItem, $strFS, 4) EndIf Next _GUICtrlListView_SetColumnWidth($hListView, 0, $LVSCW_AUTOSIZE_USEHEADER) EndIf While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete() EndFunc func String_GetFormattedSize($nBytes, $cFormat = "FMTSIZE_AUTOMATIC") local $strResult = "" if ($cFormat == "FMTSIZE_AUTOMATIC") then if ($nBytes > 1024) then if ($nBytes / 1024 < 1024) then $strResult = String(Round($nBytes / 1024, 2)) & " КБ" else if ($nBytes / 1024^2 < 1024) then $strResult = String(Round($nBytes / 1024^2, 2)) & " МБ" else if ($nBytes / 1024^3 < 1024) then $strResult = String(Round($nBytes / 1024^3, 2)) & " ГБ" else $strResult = String(Round($nBytes / 1024^4, 2)) & " ТБ" endif endif endif else $strResult = String($nBytes) endif elseif ($cFormat == "FMTSIZE_BYTES") then $strResult = String($nBytes) elseif ($cFormat == "FMTSIZE_KB") then $strResult = String(Round($nBytes / 1024, 2)) & " КБ" elseif ($cFormat == "FMTSIZE_MB") then $strResult = String(Round($nBytes / 1024^2, 2)) & " МБ" elseif ($cFormat == "FMTSIZE_GB") then $strResult = String(Round($nBytes / 1024^3, 2)) & " ГБ" elseif ($cFormat == "FMTSIZE_TB") then $strResult = String(Round($nBytes / 1024^4, 2)) & " ТБ" endif return StringReplace($strResult, ".", ",") endfunc |