Merci beaucoup !
Tu m'as encore bien avancé. Je sais pas comment tu fais pour trouver, mais tu trouves
Par contre la faisabilité est extrêmement compliquée. Je suis vraiment en train de me torturer les neurones, mais j'ai bon espoir.
Je posterai ma solution quand elle sera terminée.
PS : j'ai finalement choisi d'oublier ce que je demandais à propos de la sélection récursive, car la solution initiale correspond en fait mieux à l'utilisation qui sera faîte de l'application.
Pour ceux que ça intéresserait, sachez qu'une solution de sélection récursive existe. Voici le code :
Code : Tout sélectionner
#include <GuiTreeView.au3>
#Include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
Global $hTreeView
$hGui = GUICreate("TreeView Check All", 460, 300)
$TreeView = GUICtrlCreateTreeView(20, 20, 420, 260, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES), BitOR($WS_EX_DLGMODALFRAME,$WS_EX_CLIENTEDGE))
$hTreeView = GUICtrlGetHandle($TreeView)
BuildExampleTree($TreeView) ;just a test
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
Local $hWndFrom, $idFrom, $iCode, $tNMHDR = DllStructCreate("hwnd hwndFrom;int idFrom;int code", $lParam)
$hWndFrom = DllStructGetData($tNMHDR, "hwndFrom")
$iCode = DllStructGetData($tNMHDR, "code")
If $hWndFrom = $hTreeView Then
Switch $iCode
Case $NM_CLICK
;;$tagTVHITTESTINFO = "int X;int Y;int Flags;int Item"
Local $tMPos = _WinAPI_GetMousePos(True, $hWndFrom), $tHit = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
Local $hItem = DllStructGetData($tHit, "Item"), $iFlags = DllStructGetData($tHit, "Flags")
If $hItem <> 0 And BitAND($iFlags, $TVHT_ONITEMSTATEICON) Then
_TV_Checkbox_MultiSet($hWndFrom, $hItem, 1)
EndIf
Case $TVN_KEYDOWN
Local $tNMTVKEY = DllStructCreate("hwnd;int;int;short key;uint", $lParam)
Local $hSelected = _GUICtrlTreeView_GetSelection($hWndFrom)
If DllStructGetData($tNMTVKEY, "key") = 0x20 And $hSelected Then ;;space
_TV_Checkbox_MultiSet($hWndFrom, $hSelected, 1)
EndIf
Case Else
EndSwitch
EndIf
Return $GUI_RUNDEFMSG
EndFunc
Func _TV_Checkbox_MultiSet($hWnd, $hItem, $fTop = 0)
Local $fChecked = _GUICtrlTreeView_GetChecked($hWnd, $hItem)
If $fTop Then $fChecked = Not $fChecked
If _GUICtrlTreeView_GetChildren($hWnd, $hItem) Then
Local $hChild = _GUICtrlTreeView_GetFirstChild($hWnd, $hItem)
Do
_GUICtrlTreeView_SetChecked($hWnd, $hChild, $fChecked)
If _GUICtrlTreeView_GetChildren($hWnd, $hChild) Then
_TV_Checkbox_MultiSet($hWnd, $hChild)
EndIf
$hChild = _GUICtrlTreeView_GetNextChild($hWnd, $hChild)
Until $hChild = 0
EndIf
EndFunc
Func BuildExampleTree($treeID)
Local $ti, $tsi, $i, $j, $k
$ti = GUICtrlCreateTreeViewItem("1", $treeID)
For $i = 1 To 5
$tsi = GUICtrlCreateTreeViewItem("1-" & $i, $ti)
If $i = 3 Then
For $j = 1 To 3
$tssi = GUICtrlCreateTreeViewItem("1-" & $i & '-' & $j, $tsi)
If $j = 2 Then
For $k = 1 To 4
GUICtrlCreateTreeViewItem("1-" & $i & '-' & $j & '-' & $k, $tssi)
Next
EndIf
Next
EndIf
Next
GUICtrlCreateTreeViewItem("2", $treeID)
ControlTreeView('', '', $treeID, "Expand", '#0')
ControlTreeView('', '', $treeID, "Expand", '#0|#2')
ControlTreeView('', '', $treeID, "Expand", '#0|#2|#1')
EndFunc