Je cherchais quelque chose pour lister des dossiers, quand je suis tombé sur cela : http://www.autoitscript.fr/forum/viewto ... f=6&t=3506
Intéressant me suis dis-je
Je télécharge donc le zip associé : ShellTristateTreeView.zip
- J'ai donc l'include ShellTristateTreeView.au3
- Et le code exemple : ShellTristateTreeViewDemo.au3
► Afficher le texteInclude
Code : Tout sélectionner
#include-once
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <GuiImageList.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
;===============================================================================
;
; Program Name: ShellTristateTreeView.au3
;
; AutoIt Version: 3.2.12.1
;
; Author(s): Rasim (ShellTreeView.au3)
; Holger Kotsch (TristateTreeViewLib.au3)
; Merged & Modified version by Polyphem
; Ported to Au native filesearch and further enhancements by KaFu
;
; Note(s):
; 2008-Sep-15 Modified by KaFu from original functions
;
;===============================================================================
; You could also use an integrated bmp (with ResourceHacker)
; Please see ShellTreeView.au3 (LoadStateImage)
; If you integrate the bmp, You MUST not compile the script it full with UPX, just use after compiling: upx.exe --best --compress-resources=0 xyz.exe!
; If you choose another resource number then 170 you have to change the LoadStateImage() function
;
; You can get other check bitmaps also together with freeware install programs like i.e. NSIS
; it must have 5 image states in it:
; 1.empty, 2.unchecked, 3.checked, 4.disabled and unchecked, 5.disabled and checked
; BTW, for people who like to add icons to their treeviews with _GUICtrlTreeViewSetIcon, make certain you call LoadStateImage after _GUICtrlTreeViewSetIcon
;
; Userfunction My-WM_Notify() is registered in ShellTristateTreeView.au3.
; ----------------------------------------------------------------------------
;
; Script: Tristate TreeView
; Version: 0.3
; AutoIt Version: 3.2.0.X
; Author: Holger Kotsch
;
; Script Function:
; Demonstrates a tristate treeview control -> just more like a fifthstate treeview ; )
;
; 5 item checkbox! states are usable:
; (can only used with TreeView with TVS_CHECKBOXES-style)
; - $GUI_CHECKED
; - $GUI_UNCHECKED
; - $GUI_INDETERMINATE
; - $GUI_DISABLE + $GUI_CHECKED
; - $GUI_DISABLE + $GUI_UNCHECKED
;
; ----------------------------------------------------------------------------
If Not IsDeclared("LR_LOADFROMFILE") Then Global Const $LR_LOADFROMFILE = 0x0010
If Not IsDeclared("LR_LOADTRANSPARENT") Then Global Const $LR_LOADTRANSPARENT = 0x0020
If Not IsDeclared("LR_CREATEDIBSECTION") Then Global Const $LR_CREATEDIBSECTION = 0x2000
;If Not IsDeclared("CLR_NONE") Then Global Const $CLR_NONE = 0xFFFFFFFF
If Not IsDeclared("IMAGE_BITMAP") Then Global Const $IMAGE_BITMAP = 0
If Not IsDeclared("VK_SPACE") Then Global Const $VK_SPACE = 32
If Not IsDeclared("GWL_STYLE") Then Global Const $GWL_STYLE = -16
Global $hImage, $hImageList, $hWndTreeView, $hCommonDocs, $hMyDocs, $hMyDesktop
Global $RootItem
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 15)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 6)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 8)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 3) ; 5 = Folder closed
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 7)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4) ; 5 = Folder open
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 11) ; 6 = CD-ROM = Networkdrive connected
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 9) ; 7 = Networkdrive connected
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 10) ; 8 =Networkdrive disconnected
if FileExists(@SystemDir & "\cdfview.dll") Then
_GUIImageList_AddIcon($hImage, @SystemDir & "\cdfview.dll", 7) ; 9 = Desktop
Else
_GUIImageList_AddIcon($hImage, @SystemDir & "\CRPE32.dll", 1) ; 9 = Desktop
EndIf
; #FUNCTION# ==================================================================================================
; Name............: _ShellTreeView_Create
; Description.....: Add TreeView items with drives structures
; Syntax..........: _ShellTreeView_Create($hTreeView)
; Parameter(s)....: $hTreeView - Handle to the TreeView control
; Return value(s).: None
; Note(s).........: Tested on AutoIt 3.2.12.1 and Windows XP SP2
; Author(s).......: R.Gilman (a.k.a. rasim)
; ====================================================================================================
Func _ShellTreeView_Create($hTreeView)
Local $aDrives, $hChild, $i
_GUICtrlTreeView_BeginUpdate($hTreeView)
$hWndTreeView = $hTreeView
GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY")
_GUICtrlTreeView_SetNormalImageList($hWndTreeView, $hImage)
$RootItem = _GUICtrlTreeView_Add($hWndTreeView, 0, "My Computer (" & @ComputerName & ")", 0, 0)
$aDrives = DriveGetDrive("ALL")
dim $aDriveLabel[ubound($aDrives)]
For $i = 1 To $aDrives[0]
$aDrives[$i] = StringUpper($aDrives[$i])
if DriveGetLabel($aDrives[$i]) then
$aDriveLabel[$i] = DriveGetLabel($aDrives[$i]) & " (" & $aDrives[$i] & ")"
Else
$aDriveLabel[$i] = "(" & $aDrives[$i] & ")"
EndIf
Next
$hMyDesktop = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, "Desktop", 9, 9)
_ShellTreeView_GetSelected($hWndTreeView, _MyDesktopDir(), $hMyDesktop, false, true)
$hMyDocs = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, "My Documents", 3, 3)
_ShellTreeView_GetSelected($hWndTreeView, _MyDocumentsDir(), $hMyDocs, false, true)
$hCommonDocs = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, "Shared Documents", 3, 3)
_ShellTreeView_GetSelected($hWndTreeView, _DocumentsCommonDir(), $hCommonDocs, false, true)
For $i = 1 To $aDrives[0]
Switch DriveGetType($aDrives[$i])
Case "Removable"
If ($aDrives[$i] = "a:") Or ($aDrives[$i] = "b:") Then
$hChild = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDriveLabel[$i], 1, 1)
Else
_GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDriveLabel[$i], 4, 4)
EndIf
Case "Fixed"
$hChild = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDriveLabel[$i], 2, 2)
_ShellTreeView_GetSelected($hWndTreeView, $aDrives[$i], $hChild, false, true)
Case "CDROM"
$hChild = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDriveLabel[$i], 6, 6)
_ShellTreeView_GetSelected($hWndTreeView, $aDrives[$i], $hChild, false, true)
Case "Network"
$hChild = _GUICtrlTreeView_AddChild($hWndTreeView, $RootItem, $aDriveLabel[$i], 7, 7)
_ShellTreeView_GetSelected($hWndTreeView, $aDrives[$i], $hChild, false, true)
EndSwitch
Next
_GUICtrlTreeView_EndUpdate($hWndTreeView)
EndFunc;==>_ShellTreeView_Create
Func _DocumentsCommonDir()
local $sDocumentsCommonDir = @DocumentsCommonDir
$sDocumentsCommonDir = StringUpper(StringLeft($sDocumentsCommonDir,1)) & stringright($sDocumentsCommonDir,StringLen($sDocumentsCommonDir)-1)
if stringright($sDocumentsCommonDir,1) <> "\" then
return $sDocumentsCommonDir & "\"
Else
return $sDocumentsCommonDir
EndIf
EndFunc
Func _MyDocumentsDir()
local $sMyDocumentsDir = @MyDocumentsDir
$sMyDocumentsDir = StringUpper(StringLeft($sMyDocumentsDir,1)) & stringright($sMyDocumentsDir,StringLen($sMyDocumentsDir)-1)
if stringright($sMyDocumentsDir,1) <> "\" then
return $sMyDocumentsDir & "\"
Else
return $sMyDocumentsDir
EndIf
EndFunc
Func _MyDesktopDir()
local $sDesktopDir = @DesktopDir
$sDesktopDir = StringUpper(StringLeft($sDesktopDir,1)) & stringright($sDesktopDir,StringLen($sDesktopDir)-1)
if stringright($sDesktopDir,1) <> "\" then
return $sDesktopDir & "\"
Else
return $sDesktopDir
EndIf
EndFunc
; #FUNCTION# ==================================================================================================
; Name............: MY_WM_NOTIFY
; Description.....: Add TreeView items with directorys structures
; Handle Windows Message notifications
; Merge of the two MY_WM_NOTIFY functions from
; ShellTreeView.au3 and TristateTreeViewLib.au3
; Please don't ask me about the magic being done here in detail : )
;
; Though I'm quiet sure the function needs consolidation....
;
; ====================================================================================================
Func MY_WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
;ShellTreeView.au3
; ==========
Local $tNMHDR, $hWndFrom, $iCode
$tNMHDR = DllStructCreate($tagNMHDR, $lParam)
$hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndTreeView
Switch $iCode
Case $TVN_ITEMEXPANDINGW
Local $tINFO = DllStructCreate($tagNMTREEVIEW, $lParam)
Local $hControl = DllStructGetData($tINFO, "NewhItem")
If _GUICtrlTreeView_GetExpanded($hWndTreeView, $hControl) = False Then
_ShellTreeView_GetSelected($hWndFrom, _GUICtrlTreeView_GetText($hWndFrom, $hControl), $hControl, false, false)
EndIf
EndSwitch
EndSwitch
;TristateTreeViewLib.au3
; ==========
Local $stNmhdr = DllStructCreate("dword;int;int", $lParam)
Local $hWndFrom = DllStructGetData($stNmhdr, 1)
Local $nNotifyCode = DllStructGetData($stNmhdr, 3)
Local $hItem = 0
; Check if its treeview and only NM_CLICK and TVN_KEYDOWN
If Not BitAnd(GetWindowLong($hWndFrom, $GWL_STYLE), $TVS_CHECKBOXES) Or _
Not ($nNotifyCode = $NM_CLICK Or $nNotifyCode = $TVN_KEYDOWN) Then Return $GUI_RUNDEFMSG
If $nNotifyCode = $TVN_KEYDOWN Then
Local $lpNMTVKEYDOWN = DllStructCreate("dword;int;int;short;uint", $lParam)
; Check for 'SPACE'-press
If DllStructGetData($lpNMTVKEYDOWN, 4) <> $VK_SPACE Then Return $GUI_RUNDEFMSG
$hItem = SendMessage($hWndFrom, $TVM_GETNEXTITEM, $TVGN_CARET, 0)
Else
Local $Point = DllStructCreate("int;int")
GetCursorPos($Point)
ScreenToClient($hWndFrom, $Point)
; Check if clicked on state icon
Local $tvHit = DllStructCreate("int[2];uint;dword")
DllStructSetData($tvHit, 1, DllStructGetData($Point, 1), 1)
DllStructSetData($tvHit, 1, DllStructGetData($Point, 2), 2)
$hItem = SendMessage($hWndFrom, $TVM_HITTEST, 0, DllStructGetPtr($tvHit))
If Not BitAnd(DllStructGetData($tvHit, 2), $TVHT_ONITEMSTATEICON) Then Return $GUI_RUNDEFMSG
EndIf
If $hItem > 0 Then
Local $nState = GetItemState($hWndFrom, $hItem)
$bCheckItems = 1
If $nState = 1 Then
$nState = 1
ElseIf $nState = 2 Then
$nState = 0
ElseIf $nState = 3 Then
$nState = 1
ElseIf $nState > 3 Then
$nState = $nState - 1
$bCheckItems = 0
EndIf
SetItemState($hWndFrom, $hItem, $nState)
$nState += 1
; If item are disabled there is no chance to change it and it's parents/children
If $bCheckItems Then
CheckChildItems($hWndFrom, $hItem, $nState)
CheckParents($hWndFrom, $hItem, $nState)
EndIf
EndIf
Return "GUI_RUNDEFMSG"
EndFunc ;==>_TVN_ITEMEXPANDING
; #FUNCTION# ==================================================================================================
; Name............: _ShellTreeView_GetSelected
; Description.....: Add TreeView items with directorys structures
; Syntax..........: _ShellTreeView_GetSelected($hWndTreeView, $sDrive, $hControl)
; Parameter(s)....: $hTreeView - Handle to the TreeView control
; $sDrive - String contains drive letter or text of selected TreeView item
; $hControl - Child handle
; $bManualSelect = false - set to true to manually retrieve info on selected item, prevents update of childs
; $bInitTree = false - true for first build of tree only (see _ShellTreeView_Create())
; Return value(s).: A full path to a selected directory
; Note(s).........: Tested on AutoIt 3.2.12.1 and Windows XP SP2
; Author(s).......: R.Gilman (a.k.a. rasim)
; KaFu
; ====================================================================================================
Func _ShellTreeView_GetSelected($hWndTreeView, $sDrive, $hControl, $bManualSelect = false, $bInitTree = false)
; Handle Common Dirs
if $sDrive = "My Computer (" & @ComputerName & ")" Then return $sDrive
Switch _IsDocDir($sDrive, $hControl)
Case 1
$sDrive = _DocumentsCommonDir()
Case 2
$sDrive = _MyDocumentsDir()
Case 3
$sDrive = _MyDesktopDir()
EndSwitch
if StringInStr($sDrive,":") And $sDrive <> _DocumentsCommonDir() And $sDrive <> _MyDocumentsDir() and $sDrive <> _MyDesktopDir() Then
$sDrive = stringleft(StringRight($sDrive,3),2) & "\"
if DriveStatus(stringleft($sDrive,2)) = "NOTREADY" Then
return $sDrive
EndIf
endif
If Not FileExists($sDrive) Then
Local $hParent = _GUICtrlTreeView_GetParentHandle($hWndTreeView, $hControl), $iFullPath
If _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = "Shared Documents" Then
$iFullPath = _DocumentsCommonDir() & $sDrive
ElseIf _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = "My Documents" Then
$iFullPath = _MyDocumentsDir() & $sDrive
ElseIf _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = "Desktop" Then
$iFullPath = _MyDesktopDir() & $sDrive
Else
if StringInStr(_GUICtrlTreeView_GetText($hWndTreeView, $hParent),":") Then
$FullPathParent = stringleft(StringRight(_GUICtrlTreeView_GetText($hWndTreeView, $hParent),3),2) & "\"
Else
$FullPathParent = _GUICtrlTreeView_GetText($hWndTreeView, $hParent) & "\"
endif
$iFullPath = $FullPathParent & $sDrive
EndIf
While 1
If $hParent = 0 Then
if DriveStatus(stringleft($sDrive,2)) = "NOTREADY" Then
return $sDrive
Else
Return
endif
endif
If FileExists($iFullPath) Then
if NOT StringInStr(StringRight($iFullPath,1),"\") then $iFullPath = $iFullPath & "\"
ExitLoop
endif
$hParent = _GUICtrlTreeView_GetParentHandle($hWndTreeView, $hParent)
If _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = "Shared Documents" Then
$iFullPath = _DocumentsCommonDir() & $iFullPath
ElseIf _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = "My Documents" Then
$iFullPath = _MyDocumentsDir() & $iFullPath
ElseIf _GUICtrlTreeView_GetText($hWndTreeView, $hParent) = "Desktop" Then
$iFullPath = _MyDesktopDir() & $iFullPath
Else
if StringInStr(_GUICtrlTreeView_GetText($hWndTreeView, $hParent),":") Then
$FullPathParent = stringleft(StringRight(_GUICtrlTreeView_GetText($hWndTreeView, $hParent),3),2) & "\"
Else
$FullPathParent = _GUICtrlTreeView_GetText($hWndTreeView, $hParent) & "\"
endif
$iFullPath = $FullPathParent & $iFullPath
EndIf
WEnd
$sDrive = $iFullPath
EndIf
if $bManualSelect = false then
if FileExists($sDrive) then
_GUICtrlTreeView_BeginUpdate($hWndTreeView)
if _GUICtrlTreeView_ExpandedOnce($hWndTreeView, $hControl) = false Then
_GUICtrlTreeView_DeleteChildren($hWndTreeView, $hControl)
_GetFolders($hWndTreeView, $hControl, $sDrive, $bInitTree)
EndIf
_GUICtrlTreeView_EndUpdate($hWndTreeView)
endif
EndIf
Return $sDrive
EndFunc ;==>_ShellTreeView_GetSelected
Func _GetFolders($hWndTreeView, $hControl, $sDrive, $bInitTree)
$hSearch = FileFindFirstFile($sDrive & "\*.*")
While Not @error ; first file found
$sFiles = FileFindNextFile($hSearch)
If @error Then ExitLoop ; next file found
$sAttrib = FileGetAttrib($sDrive & $sFiles)
If StringInStr($sAttrib, "D") Then
$iSubChild = _GUICtrlTreeView_AddChild($hWndTreeView, $hControl, $sFiles, 3, 5)
if MyCtrlGetItemState($hWndTreeView, $hControl) <> 4 then MyCtrlSetItemState($hWndTreeView, $iSubChild, MyCtrlGetItemState($hWndTreeView, $hControl))
if $bInitTree = false then
$hSearchSub = FileFindFirstFile($sDrive & $sFiles & "\*.*")
While Not @error ; first subfile found
$sFilesSub = FileFindNextFile($hSearchSub)
If @error Then ExitLoop ; next file found
$sAttrib = FileGetAttrib($sDrive & $sFiles & "\" & $sFilesSub)
If StringInStr($sAttrib, "D") Then
$iSubChildsub = _GUICtrlTreeView_AddChild($hWndTreeView, $iSubChild, $sFilesSub, 3, 5)
if MyCtrlGetItemState($hWndTreeView, $iSubChild) <> 4 then MyCtrlSetItemState($hWndTreeView, $iSubChildsub, MyCtrlGetItemState($hWndTreeView, $iSubChild))
endif
WEnd
FileClose($hSearchSub)
endif
EndIf
WEnd
FileClose($hSearch)
EndFunc
Func _IsDocDir($sPath, $hControl)
If $sPath = "Shared Documents" And ($hControl = $hCommonDocs) Then
Return 1
ElseIf $sPath = "My Documents" And ($hControl = $hMyDocs) Then
Return 2
ElseIf $sPath = "Desktop" And ($hControl = $hMyDesktop) Then
Return 3
Else
Return False
EndIf
EndFunc ;==>_IsDocDir
;**********************************************************
; Get an item state
;**********************************************************
Func MyCtrlGetItemState($hTV, $nID)
$nState = GetItemState($hTV, $nID)
Switch $nState
Case 1
$nState = $GUI_UNCHECKED
Case 2
$nState = $GUI_CHECKED
Case 3
$nState = $GUI_INDETERMINATE
Case 4
$nState = BitOr($GUI_DISABLE, $GUI_UNCHECKED)
Case 5
$nState = BitOr($GUI_DISABLE, $GUI_CHECKED)
Case Else
Return 0
EndSwitch
Return $nState
EndFunc
;**********************************************************
; Set an item state
;**********************************************************
Func MyCtrlSetItemState($hTV, $nID, $nState)
Switch $nState
Case $GUI_UNCHECKED
$nState = 1
Case $GUI_CHECKED
$nState = 2
Case $GUI_INDETERMINATE
$nState = 3
Case BitOr($GUI_DISABLE, $GUI_UNCHECKED)
$nState = 4
Case BitOr($GUI_DISABLE, $GUI_CHECKED)
$nState = 5
Case Else
Return
EndSwitch
SetItemState($hTV, $nID, $nState)
CheckChildItems($hTV, $nID, $nState)
CheckParents($hTV, $nID, $nState)
EndFunc
;**********************************************************
; Helper functions
;**********************************************************
Func CheckChildItems($hWnd, $hItem, $nState)
Local $hChild = SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $hItem)
While $hChild > 0
SetItemState($hWnd, $hChild, $nState)
CheckChildItems($hWnd, $hChild, $nState)
$hChild = SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXT, $hChild)
WEnd
EndFunc
Func CheckParents($hWnd, $hItem, $nState)
Local $nTmpState1 = 0, $nTmpState2 = 0
Local $bDiff = 0
Local $i = 0
Local $hParent = SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_PARENT, $hItem)
If $hParent > 0 Then
Local $hChild = SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_CHILD, $hParent)
If $hChild > 0 Then
Do
$i = $i + 1
If $hChild = $hItem Then
$nTmpState2 = $nState
Else
$nTmpState2 = GetItemState($hWnd, $hChild)
EndIf
If $i = 1 Then $nTmpState1 = $nTmpState2
If $nTmpState1 <> $nTmpState2 Then
$bDiff = 1
ExitLoop
EndIf
$hChild = SendMessage($hWnd, $TVM_GETNEXTITEM, $TVGN_NEXT, $hChild)
Until $hChild <= 0
If $bDiff Then
SetItemState($hWnd, $hParent, 3)
$nState = 3
Else
SetItemState($hWnd, $hParent, $nState)
EndIf
EndIf
CheckParents($hWnd, $hParent, $nState)
EndIf
EndFunc
Func SetItemState($hWnd, $hItem, $nState)
$nState = BitShift($nState, -12)
Local $tvItem = DllStructCreate("uint;dword;uint;uint;ptr;int;int;int;int;int;int")
DllStructSetData($tvItem, 1, $TVIF_STATE)
DllStructSetData($tvItem, 2, $hItem)
DllStructSetData($tvItem, 3, $nState)
DllStructSetData($tvItem, 4, $TVIS_STATEIMAGEMASK)
SendMessage($hWnd, $TVM_SETITEMW, 0, DllStructGetPtr($tvItem))
EndFunc
Func GetItemState($hWnd, $hItem)
Local $tvItem = DllStructCreate("uint;dword;uint;uint;ptr;int;int;int;int;int;int")
DllStructSetData($tvItem, 1, $TVIF_STATE)
DllStructSetData($tvItem, 2, $hItem)
DllStructSetData($tvItem, 4, $TVIS_STATEIMAGEMASK)
SendMessage($hWnd, $TVM_GETITEMW, 0, DllStructGetPtr($tvItem))
Local $nState = DllStructGetData($tvItem, 3)
$nState = BitAnd($nState, $TVIS_STATEIMAGEMASK)
$nState = BitShift($nState, 12)
Return $nState
EndFunc
Func LoadStateImage($hTreeView, $sFile)
Local $hWnd = GUICtrlGetHandle($hTreeView)
If $hWnd = 0 Then $hWnd = $hTreeView
Local $hImageList = 0
If @Compiled Then
Local $hModule = LoadLibrary(@ScriptFullPath)
$hImageList = ImageList_LoadImage($hModule, "#170", 16, 1, $CLR_NONE, $IMAGE_BITMAP, BitOr($LR_LOADTRANSPARENT, $LR_CREATEDIBSECTION))
Else
$hImageList = ImageList_LoadImage(0, $sFile, 16, 1, $CLR_NONE, $IMAGE_BITMAP, BitOr($LR_LOADFROMFILE, $LR_LOADTRANSPARENT, $LR_CREATEDIBSECTION))
EndIf
SendMessage($hWnd, $TVM_SETIMAGELIST, $TVSIL_STATE, $hImageList)
InvalidateRect($hWnd, 0, 1)
EndFunc
;**********************************************************
; Win32-API functions
;**********************************************************
Func SendMessage($hWnd, $Msg, $wParam, $lParam)
$nResult = DllCall("user32.dll", "int", "SendMessage", _
"hwnd", $hWnd, _
"int", $Msg, _
"int", $wParam, _
"int", $lParam)
Return $nResult[0]
EndFunc
Func GetWindowLong($hWnd, $nIndex)
$nResult = DllCall("user32.dll", "int", "GetWindowLong", "hwnd", $hWnd, "int", $nIndex)
Return $nResult[0]
EndFunc
Func GetCursorPos($Point)
DllCall("user32.dll", "int", "GetCursorPos", "ptr", DllStructGetPtr($Point))
EndFunc
Func ScreenToClient($hWnd, $Point)
DllCall("user32.dll", "int", "ScreenToClient", "hwnd", $hWnd, "ptr", DllStructGetPtr($Point))
EndFunc
Func InvalidateRect($hWnd, $lpRect, $bErase)
DllCall("user32.dll", "int", "InvalidateRect", _
"hwnd", $hWnd, _
"ptr", $lpRect, _
"int", $bErase)
EndFunc
Func LoadLibrary($sFile)
Local $hModule = DllCall("kernel32.dll", "hwnd", "LoadLibrary", "str", $sFile)
Return $hModule[0]
EndFunc
Func ImageList_LoadImage($hInst, $sFile, $cx, $cGrow, $crMask, $uType, $uFlags)
Local $hImageList = DllCall("comctl32.dll", "hwnd", "ImageList_LoadImage", _
"hwnd", $hInst, _
"str", $sFile, _
"int", $cx, _
"int", $cGrow, _
"int", $crMask, _
"int", $uType, _
"int", $uFlags)
Return $hImageList[0]
EndFunc
Func DestroyImageList()
DllCall("comctl32.dll", "int", "ImageList_Destroy", "hwnd", $hImageList)
EndFunc► Afficher le texteScript exemple
Code : Tout sélectionner
#include<GuiConstantsEx.au3>
#include<WindowsConstants.au3>
#include<GuiTreeView.au3>
#include<ShellTristateTreeView.au3>
#include<Array.au3>
#include<WinAPI.au3>
;===============================================================================
;
; Program Name: ShellTristateTreeViewDemo.au3
; Userfunction My-WM_Notify() is registered in ShellTristateTreeView.au3.
;
; AutoIt Version: 3.2.12.1
;
; Author(s): Rasim (ShellTreeView.au3)
; Holger Kotsch (TristateTreeViewLib.au3)
; Merged & Modified by Polyphem
; Ported to Au native filesearch and further enhancements by KaFu
;
; Note(s):
; 2008-Sep-15 Modified by KaFu from original functions
;===============================================================================
Global $sStateIconFile = @ScriptDir & "\modern.bmp"
Global $aTreeViewItemState[1][1],$aTreeViewItemStateChecked[1][1]
$hGUI = GUICreate("ShellTristateTreeView Demo", 300, 340)
$ButtonSelected = GUICtrlCreateButton("Selected Item", 10, 300, 80, 23)
$ButtonCheckedStats = GUICtrlCreateButton("Checked Status", 110, 300, 80, 23)
$ButtonCheckedFull = GUICtrlCreateButton("Checked Full", 210, 300, 80, 23)
$hTreeView = _GUICtrlTreeView_Create($hGUI, 20, 20, 260, 260, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT,$TVS_DISABLEDRAGDROP, $TVS_CHECKBOXES),$WS_EX_CLIENTEDGE)
_GUICtrlTreeView_BeginUpdate($hTreeView)
_ShellTreeView_Create($hTreeView)
_GUICtrlTreeView_SetState($hTreeView, _GUICtrlTreeView_GetFirstItem($hTreeView),$TVIS_EXPANDED,true)
_ShellTreeView_GetSelected($hTreeView, _GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetFirstItem($hTreeView)), _GUICtrlTreeView_GetFirstItem($hTreeView))
_GUICtrlTreeView_EndUpdate($hTreeView)
GUISetState()
LoadStateImage($hTreeView, $sStateIconFile)
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
Exit
Case $ButtonSelected
$hSelect = _GUICtrlTreeView_GetSelection($hTreeView)
If $hSelect Then
$sText = _GUICtrlTreeView_GetText($hTreeView, $hSelect)
MsgBox(64, "ShellTristateTreeViewDemo - Info", _ShellTreeView_GetSelected($hTreeView, $sText, $hSelect, true))
EndIf
Case $ButtonCheckedStats
GUISetState(@SW_LOCK)
$iCountState = 0
redim $aTreeViewItemState[_GUICtrlTreeView_GetCount($hTreeView)][2]
$hItem = _GUICtrlTreeView_GetFirstItem($hTreeView)
while $hItem
if $iCountState = 0 Then
$aTreeViewItemState[$iCountState][0] = "My Computer"
Else
$sText = _GUICtrlTreeView_GetText($hTreeView, $hItem)
$aTreeViewItemState[$iCountState][0] = _ShellTreeView_GetSelected($hTreeView, $sText, $hItem, true)
EndIf
$aTreeViewItemState[$iCountState][1] = MyCtrlGetItemState($hTreeView,$hItem)
$iCountState += 1
$hItem = _GUICtrlTreeView_GetNext($hTreeView, $hItem)
WEnd
GUISetState(@SW_UNLOCK)
_ArrayDisplay($aTreeViewItemState)
Case $ButtonCheckedFull
GUISetState(@SW_LOCK)
$aTreeViewItemState = ""
dim $aTreeViewItemState[_GUICtrlTreeView_GetCount($hTreeView)][2]
$hItemRoot = _GUICtrlTreeView_GetFirstItem($hTreeView)
$aTreeViewItemState[0][0] = "My Computer"
$aTreeViewItemState[0][1] = MyCtrlGetItemState($hTreeView,$hItemRoot)
$iCountStateChecked = 1
if MyCtrlGetItemState($hTreeView, $hItemRoot) = 1 Then ; if "My Computer" is activated
$hItemSub = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItemRoot)
While $hItemSub
$iCountStateChecked += 1
$sText = _GUICtrlTreeView_GetText($hTreeView, $hItemSub)
$aTreeViewItemState[$iCountStateChecked][0] = _ShellTreeView_GetSelected($hTreeView, $sText, $hItemSub, true)
$aTreeViewItemState[$iCountStateChecked][1] = MyCtrlGetItemState($hTreeView,$hItemSub)
$hItemSub = _GUICtrlTreeView_GetNextChild($hTreeView, $hItemSub)
WEnd
ElseIf MyCtrlGetItemState($hTreeView, $hItemRoot) = 2 Then ; if anything else is activated
_TreeviewGetChildState($hTreeView, $hItemRoot, $iCountStateChecked)
EndIf
; Parse and clean the results, just keep top-most parent directories activated and skip childs
_ArrayDelete($aTreeViewItemState,0)
_ArraySort($aTreeViewItemState,1)
for $iCountStateChecked = ubound($aTreeViewItemState)-1 to 1 step -1
if stringlen($aTreeViewItemState[$iCountStateChecked][0]) = 0 then _ArrayDelete($aTreeViewItemState,$iCountStateChecked)
Next
_ArraySort($aTreeViewItemState)
for $i = 0 to UBound($aTreeViewItemState)-2
if $i = UBound($aTreeViewItemState) - 1 then ExitLoop
if StringInStr($aTreeViewItemState[$i+1][0],$aTreeViewItemState[$i][0]) then
_ArrayDelete($aTreeViewItemState,$i+1)
$i = $i -1
endif
Next
GUISetState(@SW_UNLOCK)
if stringlen($aTreeViewItemState[0][0]) = 0 then
MsgBox(64,"ShellTristateTreeView Demo","Nothing selected...")
Else
_ArrayDisplay($aTreeViewItemState)
endif
EndSwitch
WEnd
Func _TreeviewGetChildState($hTreeView, $hItem, $iCountStateChecked)
Local $hItemSub
$hItemSub = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem)
While $hItemSub
if MyCtrlGetItemState($hTreeView, $hItemSub) = 2 Then
$iCountStateChecked = _TreeviewGetChildState($hTreeView, $hItemSub, $iCountStateChecked)
ElseIf MyCtrlGetItemState($hTreeView, $hItemSub) = 1 Then
$iCountStateChecked += 1
$sText = _GUICtrlTreeView_GetText($hTreeView, $hItemSub)
$aTreeViewItemState[$iCountStateChecked][0] = _ShellTreeView_GetSelected($hTreeView, $sText, $hItemSub, true)
$aTreeViewItemState[$iCountStateChecked][1] = MyCtrlGetItemState($hTreeView,$hItemSub)
endif
$hItemSub = _GUICtrlTreeView_GetNextChild($hTreeView, $hItemSub)
WEnd
Return $iCountStateChecked
EndFunc
J'ai testé, et je suis venu à ces conclusions :
En fait, quand je clique sur la case, et que je clique sur selected item, je n'ai pas la bonne information.
Par contre, quand je sélectionne en cliquant directement sur l'item, sans passer par la case (je met l'item en surbrillance), l'appui sur le bouton selected item m'envoie la bonne information.
J'ai donc essayé de voir si je trouvais pas un moyen de, au moment de cliquer sur la case, mettre l'item sur surbrillance également.
Mais je ne sais pas où modifier, et encore moins ce que je dois modifier.
Ce treeview, si j'y arrive, sera à mettre en place sur un outil que j'ai déjà bien avancé.
Pouvez-vous m'aider ?
Merci pour vos futures réponses :cheers:
@++


