► Afficher le texte
Code : Tout sélectionner
#include <StructureConstants.au3>
#include <GuiImageList.au3>
#include <TreeViewConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <File.au3>
#include <ListviewConstants.au3>
$sPath = 'C:'
$sPathh = 'D:'
$hGui = GUICreate('BackUp Station', 459, 708, 772, 22)
$Pic1 = GUICtrlCreatePic("index1.jpg", 304, 8, 124, 60)
$hTreeview = GUICtrlCreateTreeView(10, 74, 436, 568, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES))
$hWndTreeview = GUICtrlGetHandle($hTreeview)
$hOk = GUICtrlCreateButton('Sauvegarde', 16, 663, 92, 22)
$hCancel = GUICtrlCreateButton('Restauration', 184, 663, 100, 22)
$hAide = GUICtrlCreateButton('Aide', 352, 663, 92, 22)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, 'shell32.dll', 4)
_GUIImageList_AddIcon($hImage, 'shell32.dll', 1)
_GUICtrlTreeView_SetNormalImageList($hTreeview, $hImage)
GUISetState()
GUICtrlSetStyle($hTreeview, Default, $WS_EX_COMPOSITED + $WS_EX_CLIENTEDGE)
;~ ######################################################################################################################## integration des repertoires
$hRoot = _GUICtrlTreeView_Add($hTreeview, $hTreeview, $sPath, 0, 0)
_GUICtrlTreeView_SetChecked($hTreeview, $hRoot)
_GUICtrlTreeView_SetState($hTreeview, $hRoot, $TVIS_EXPANDED)
$hRoot1 = _GUICtrlTreeView_Add($hTreeview, $hTreeview, $sPathh, 0, 0)
_GUICtrlTreeView_SetChecked($hTreeview, $hRoot1)
_GUICtrlTreeView_SetState($hTreeview, $hRoot, $TVIS_EXPANDED)
;~ ######################################################################################################################## arborescence des repertoires
_GUICtrlTreeView_BeginUpdate($hTreeview)
GUISetCursor(15, 1, $hGui)
_GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hRoot, $sPath, 2)
GUISetCursor(2, 1, $hGui)
_GUICtrlTreeView_EndUpdate($hTreeview)
_GUICtrlTreeView_BeginUpdate($hTreeview)
GUISetCursor(15, 1, $hGui)
_GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hRoot1, $sPathh, 2)
GUISetCursor(2, 1, $hGui)
_GUICtrlTreeView_EndUpdate($hTreeview)
;~ ######################################################################################################################## Fonction
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
GUIRegisterMsg($WM_NOTIFY, '')
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
$iCode = DllStructGetData($tNMHDR, 'Code')
If $hWndFrom = $hWndTreeview And $iCode = $NM_CLICK Then
ToolTip('Chargement...', Default, Default, 'Lecture', 1)
_GUICtrlTreeView_FileExplorer($hGui, $hTreeview)
ToolTip('')
EndIf
GUIRegisterMsg($WM_NOTIFY, '_WM_NOTIFY')
Return $GUI_RUNDEFMSG
EndFunc
;~ ######################################################################################################################## Fonction
Func _GUICtrlTreeView_FileExplorer($hGui, $hTreeview)
Local $aTVPos, $aPos, $hItem, $hChild, $sTree
$aTVPos = ControlGetPos($hGui, '', $hTreeview)
$aPos = GUIGetCursorInfo($hGui)
$check= GUICtrlSetState(-1, $GUI_CHECKED)
$hItem = _GUICtrlTreeView_HitTestItem($hTreeview, $aPos[0], $aPos[1] - $aTVPos[1])
If _GUICtrlTreeView_GetExpanded($hTreeview, $hItem) Then Return
$hChild = _GUICtrlTreeView_GetFirstChild($hTreeview, $hItem)
_GUICtrlTreeView_BeginUpdate($hTreeview)
If $hChild <> 0 Then
$sTree = StringReplace(_GUICtrlTreeView_GetTree($hTreeview, $hChild), '|', '\')
_GUICtrlTreeView_DeleteChildren($hTreeview, $hChild)
_GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hChild, $sTree, 1)
EndIf
Do
$hChild = _GUICtrlTreeView_GetNextChild($hTreeview, $hChild)
If $hChild <> 0 Then
$sTree = StringReplace(_GUICtrlTreeView_GetTree($hTreeview, $hChild), '|', '\')
_GUICtrlTreeView_DeleteChildren($hTreeview, $hChild)
$iTimer = TimerInit()
_GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hChild, $sTree, 1)
EndIf
Until $hChild = 0
_GUICtrlTreeView_EndUpdate($hTreeview)
EndFunc ;==>_GUICtrlTreeView_FileExplorer
;~ ######################################################################################################################## Fonction
Func _GUICtrlTreeView_FileExplorerRecursive($hTreeview, $hItem, $sPath, $iRec)
Local $aDirList, $aFileList, $tmp, $hIcon
$iRec -= 1
$aDirList = _FileListToArray($sPath, '*', 2)
If IsArray($aDirList) Then
For $i = 1 To $aDirList[0]
If Not StringInStr(FileGetAttrib($sPath & '\' & $aDirList[$i]), 's') Then
$tmp = _GUICtrlTreeView_AddChild($hTreeview, $hItem, $aDirList[$i], 0, 0)
_GUICtrlTreeView_SetChecked($hTreeview, $tmp)
If $iRec > 0 Then _GUICtrlTreeView_FileExplorerRecursive($hTreeview, $tmp, $sPath & '\' & $aDirList[$i], $iRec)
EndIf
Next
EndIf
$aFileList = _FileListToArray($sPath, '*', 1)
If IsArray($aFileList) Then
For $i = 1 To $aFileList[0]
If Not StringInStr(FileGetAttrib($sPath & '\' & $aFileList[$i]), 's') Then
$hIcon = _GUIImageList_AddIcon($hImage, $sPath & '\' & $aFileList[$i], 0)
If $hIcon = 0 Then
$hIcon = 1
Else
_GUICtrlTreeView_SetNormalImageList($hTreeview, $hImage)
EndIf
$tmp = _GUICtrlTreeView_AddChild($hTreeview, $hItem, $aFileList[$i], $hIcon, $hIcon)
_GUICtrlTreeView_SetChecked($hTreeview, $tmp)
EndIf
Next
EndIf
EndFunc ;==>_GUICtrlTreeView_FileExplorerRecursive
;~ ######################################################################################################################## Function des Périphériques Externes
Local $sDrives
Local $aUSBDrives = _ListUSBVolumes()
Func _ListUSBVolumes()
Local $aResult[1]
Local $oDrive, $sDeviceID, $oPartitions, $oPartition, $oLogicalDisks, $oLogicalDisk, $sDriveLetter
Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
Local $oDiskDrives = $oWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive Where InterfaceType = 'USB'")
For $oDrive In $oDiskDrives
$sDeviceID = StringReplace($oDrive.DeviceID, "\", "\\")
$oPartitions = $oWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
$sDeviceID & """} WHERE AssocClass = " & _
"Win32_DiskDriveToDiskPartition")
For $oPartition In $oPartitions
$oLogicalDisks = $oWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
$oPartition.DeviceID & """} WHERE AssocClass = " & _
"Win32_LogicalDiskToPartition")
For $oLogicalDisk In $oLogicalDisks
$sDriveLetter = $oLogicalDisk.DeviceID
If $sDriveLetter <> "" Then
Redim $aResult[ UBound($aResult) + 1]
$aResult[ UBound($aResult) - 1] = $sDriveLetter
EndIf
Next
Next
Next
$aResult[0] = UBound($aResult) - 1
Return $aResult
EndFunc
;~ ######################################################################################################################## option des boutons
GUIRegisterMsg($WM_NOTIFY, '_WM_NOTIFY')
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $hCancel
Exit
Case $hOk
;~ ######### Detection des cases non cocher
$txt = ""
$h = _GUICtrlTreeView_GetFirstItem($hTreeview)
Do
If not _GUICtrlTreeView_GetChecked($hTreeview, $h) Then _
$txt &= StringReplace(_GUICtrlTreeView_GetTree($hTreeview, $h), '|', '\') & @crlf
$h = _GUICtrlTreeView_GetNext($hTreeview, $h)
Until not $h
MsgBox(0, "Eléments non sauvegarder", $txt)
;~ #####Demande du choix du périphériques de sauvegarde + Calcul de la taille des Périphériques
For $i = 1 To $aUSBDrives[0]
$sDrives &= $aUSBDrives[$i] & @TAB & DriveGetLabel($aUSBDrives[$i]) & @CRLF
$taille = DirGetSize ($sDrives)
Next
MsgBox(0, "USB Drives", "Liste des volumes de type USB : " & @CRLF & $sDrives )
;~ #####
Case $hAide
$Aide_txt = "Aide.txt"
run("notepad Aide.txt")
EndSwitch
WEndMerci d'avance
Thomas




