Что нового

Составить дерево TreeView из спика INI

Centrinar

Новичок
Сообщения
100
Репутация
1
Версия AutoIt: 3.3.6.1 и выше

Описание:
Есть INI файл типа:
all
arhiv1=test.rar
1C
arhiv1=test2.rar

Необходимо дерево в котором есть папки all и 1С и в них файл arhiv1 и arhiv2 соответственно. В основном проблема возникает что бы возле каждого элемента была возможность поставить ЧЕКБОКС т.е. если отметить папку all то отмечаются все файл которые в этом разделе. И вторая проблема что бы при нажатии Button , запускались поочередно архивы tets.rar, test2.rar если отмечены arhiv1 и arhiv2 соответственно. спасибо!
Примечания:
 

kaster

Мой Аватар, он лучший самый
Команда форума
Глобальный модератор
Сообщения
4,020
Репутация
626
OffTopic:
на будущее: достаточно было поправить первое сообщение в старой теме и я бы ее перенес.
 

madmasles

Модератор
Глобальный модератор
Сообщения
7,790
Репутация
2,322
Centrinar,
Не знаю насколько правильно, это мой практически первый опыт с TreeView, но у меня работает. В прикрепленном архиве test.ini.
Код:
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

$iClm = 0
$sIniFile = @ScriptDir & '\test.ini'
$aSection = IniReadSectionNames($sIniFile)
Dim $aData[$aSection[0] + 1][2]
For $i = 1 To $aSection[0]
	$aTemp = IniReadSection($sIniFile, $aSection[$i])
	$aData[$i][0] = $aSection[$i]
	If $iClm < $aTemp[0][0] Then
		$iClm = $aTemp[0][0]
		ReDim $aData[$aSection[0] + 1][$iClm + 1]
	EndIf
	For $j = 1 To $aTemp[0][0]
		$aData[$i][$j] = $aTemp[$j][1]
	Next
Next
$aData[0][0] = $aSection[0]
$aData[0][1] = $iClm

Dim $a_hItem[$aData[0][0] + 1][$iClm + 3] = [[$aData[0][0], $iClm]]

$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, _
		$TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)

$hGUI = GUICreate('Test', 400, 300, -1, -1, -1, $WS_CLIPCHILDREN)
$nButton = GUICtrlCreateButton('Click me', 150, 260, 100, 30)
$hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 250, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')

_GUICtrlTreeView_BeginUpdate($hTreeView)
For $i = 1 To $a_hItem[0][0]
	$a_hItem[$i][0] = _GUICtrlTreeView_Add($hTreeView, 0, $aData[$i][0], $i)
	For $j = 1 To $a_hItem[0][1]
		If $aData[$i][$j] Then
			$a_hItem[$i][$j] = _GUICtrlTreeView_AddChild($hTreeView, $a_hItem[$i][0], $aData[$i][$j], $j)
		Else
			ExitLoop
		EndIf
	Next
	$a_hItem[$i][$a_hItem[0][1] + 2] = True
Next
_GUICtrlTreeView_EndUpdate($hTreeView)

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $nButton
			$iCount = 0
			Dim $aData[1][2]
			For $i = 1 To $a_hItem[0][0]
				For $j = 1 To $a_hItem[0][1]
					If $a_hItem[$i][$j] Then
						If _GUICtrlTreeView_GetChecked($hTreeView, $a_hItem[$i][$j]) Then
							$iCount += 1
							ReDim $aData[$iCount + 1][2]
							$aData[$iCount][0] = _GUICtrlTreeView_GetText($hTreeView, $a_hItem[$i][0])
							$aData[$iCount][1] = _GUICtrlTreeView_GetText($hTreeView, $a_hItem[$i][$j])
						EndIf
					EndIf
				Next
			Next
			If $iCount Then
				$aData[0][0] = $iCount
				_ArrayDisplay($aData)
				;здесь делайте с отмеченными Item то, что Вам надо.
			Else
				MsgBox(16, 'Error', 'Нет отмеченных')
			EndIf
	EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
	#forceref $hWnd, $iMsg, $iwParam
	Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $fChecked
	$hWndTreeview = $hTreeView
	If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
	$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
	$hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
	$iCode = DllStructGetData($tNMHDR, 'Code')
	Switch $hWndFrom
		Case $hWndTreeview
			Switch $iCode
				Case $NM_CUSTOMDRAW
					For $i = 1 To $a_hItem[0][0]
						$a_hItem[$i][$a_hItem[0][1] + 2] = _GUICtrlTreeView_GetChecked($hWndFrom, $a_hItem[$i][0])
						If $a_hItem[$i][$a_hItem[0][1] + 1] <> $a_hItem[$i][$a_hItem[0][1] + 2] Then
							$a_hItem[$i][$a_hItem[0][1] + 1] = $a_hItem[$i][$a_hItem[0][1] + 2]
							For $j = 1 To $a_hItem[0][1]
								If $a_hItem[$i][$j] Then
									_GUICtrlTreeView_SetChecked($hWndFrom, $a_hItem[$i][$j], $a_hItem[$i][$a_hItem[0][1] + 1])
								EndIf
							Next
						EndIf
					Next
					Return 0
			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
 
Автор
C

Centrinar

Новичок
Сообщения
100
Репутация
1
Изменил немного ИНИ и сам скрипт, работает но сортирует только половину записей, если не сложно гляньте, где ошибка?
Код:
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $sIniFile = @ScriptDir & '\test.ini'
$aParams = IniReadSection($sIniFile, "Arhives")
Global $iTotalParams = UBound($aParams)-1
Global $Progs[$iTotalParams + 1]

$aParams2 = IniReadSection($sIniFile, "Test")
Global $iTotalParams2 = UBound($aParams2)-1
Global $Progs2[$iTotalParams2 + 1]

Dim $a_hItem[$iTotalParams + 1][$iTotalParams2 + 3] = [[$iTotalParams , $iTotalParams2]]

$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, _
        $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)


$hGUI = GUICreate('Test', 400, 300, -1, -1, -1, $WS_CLIPCHILDREN)
$nButton = GUICtrlCreateButton('Click me', 150, 260, 100, 30)
$hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 250, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')


_GUICtrlTreeView_BeginUpdate($hTreeView)

For $i = 1 To $iTotalParams

	$aData = IniRead($sIniFile, "Arhives", "Arhives" & $i, "")
    $a_hItem[$i][0] = _GUICtrlTreeView_Add($hTreeView, 0, $aData)

    For $j = 1 To $iTotalParams2
	  $parse = StringRegExp(IniRead($sIniFile,"Test","test"&$j,"<de.exe><INI file ?><0>"),"<(.*?)>",3)

		If $parse[3] =  $aData Then

		   $a_hItem[$i][$j] = _GUICtrlTreeView_AddChild($hTreeView, $a_hItem[$i][0], $parse[1])
        Else
            ExitLoop
        EndIf
	Next
	$a_hItem[$i][$a_hItem[0][1] + 2] = True
Next

_GUICtrlTreeView_EndUpdate($hTreeView)




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nButton
            $iCount = 0
            Dim $aData[1][2]
            For $i = 1 To $a_hItem[0][0]
                For $j = 1 To $a_hItem[0][1]
                    If $a_hItem[$i][$j] Then
                        If _GUICtrlTreeView_GetChecked($hTreeView, $a_hItem[$i][$j]) Then
                            $iCount += 1
                            ReDim $aData[$iCount + 1][2]
                            $aData[$iCount][0] = _GUICtrlTreeView_GetText($hTreeView, $a_hItem[$i][0])
                            $aData[$iCount][1] = _GUICtrlTreeView_GetText($hTreeView, $a_hItem[$i][$j])
                        EndIf
                    EndIf
                Next
            Next
            If $iCount Then
                $aData[0][0] = $iCount
                _ArrayDisplay($aData)
                ;здесь делайте с отмеченными Item то, что Вам надо.
            Else
                MsgBox(16, 'Error', 'Нет отмеченных')
            EndIf
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $fChecked
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
    $iCode = DllStructGetData($tNMHDR, 'Code')
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    For $i = 1 To $a_hItem[0][0]
                        $a_hItem[$i][$a_hItem[0][1] + 2] = _GUICtrlTreeView_GetChecked($hWndFrom, $a_hItem[$i][0])
                        If $a_hItem[$i][$a_hItem[0][1] + 1] <> $a_hItem[$i][$a_hItem[0][1] + 2] Then
                            $a_hItem[$i][$a_hItem[0][1] + 1] = $a_hItem[$i][$a_hItem[0][1] + 2]
                            For $j = 1 To $a_hItem[0][1]
                                If $a_hItem[$i][$j] Then
                                    _GUICtrlTreeView_SetChecked($hWndFrom, $a_hItem[$i][$j], $a_hItem[$i][$a_hItem[0][1] + 1])
                                EndIf
                            Next
                        EndIf
                    Next
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY


ИНИ прилагается
:IL_AutoIt_1:
 
Автор
C

Centrinar

Новичок
Сообщения
100
Репутация
1
Дерево составляется из ИНИ файла
Скрипт:
Код:
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $sIniFile = @ScriptDir & '\test.ini'
$aParams = IniReadSection($sIniFile, "Arhives")
Global $iTotalParams = UBound($aParams)-1
Global $Progs[$iTotalParams + 1]

$aParams2 = IniReadSection($sIniFile, "Test")
Global $iTotalParams2 = UBound($aParams2)-1
Global $Progs2[$iTotalParams2 + 1]

Dim $a_hItem[$iTotalParams + 1][$iTotalParams2 + 3] = [[$iTotalParams , $iTotalParams2]]

$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, _
        $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)


$hGUI = GUICreate('Test', 400, 300, -1, -1, -1, $WS_CLIPCHILDREN)
$nButton = GUICtrlCreateButton('Click me', 150, 260, 100, 30)
$hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 250, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')


_GUICtrlTreeView_BeginUpdate($hTreeView)

For $i = 1 To $iTotalParams

    $aData = IniRead($sIniFile, "Arhives", "Arhives" & $i, "")
    $a_hItem[$i][0] = _GUICtrlTreeView_Add($hTreeView, 0, $aData)

    For $j = 1 To $iTotalParams2
      $parse = StringRegExp(IniRead($sIniFile,"Test","test"&$j,"<de.exe><INI file ?><0>"),"<(.*?)>",3)

        If $parse[3] =  $aData Then

           $a_hItem[$i][$j] = _GUICtrlTreeView_AddChild($hTreeView, $a_hItem[$i][0], $parse[1])
        Else
            ExitLoop
        EndIf
    Next
    $a_hItem[$i][$a_hItem[0][1] + 2] = True
Next

_GUICtrlTreeView_EndUpdate($hTreeView)




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $nButton
            $iCount = 0
            Dim $aData[1][2]
            For $i = 1 To $a_hItem[0][0]
                For $j = 1 To $a_hItem[0][1]
                    If $a_hItem[$i][$j] Then
                        If _GUICtrlTreeView_GetChecked($hTreeView, $a_hItem[$i][$j]) Then
                            $iCount += 1
                            ReDim $aData[$iCount + 1][2]
                            $aData[$iCount][0] = _GUICtrlTreeView_GetText($hTreeView, $a_hItem[$i][0])
                            $aData[$iCount][1] = _GUICtrlTreeView_GetText($hTreeView, $a_hItem[$i][$j])
                        EndIf
                    EndIf
                Next
            Next
            If $iCount Then
                $aData[0][0] = $iCount
                _ArrayDisplay($aData)
                ;здесь делайте с отмеченными Item то, что Вам надо.
            Else
                MsgBox(16, 'Error', 'Нет отмеченных')
            EndIf
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $fChecked
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
    $iCode = DllStructGetData($tNMHDR, 'Code')
    Switch $hWndFrom
        Case $hWndTreeview
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    For $i = 1 To $a_hItem[0][0]
                        $a_hItem[$i][$a_hItem[0][1] + 2] = _GUICtrlTreeView_GetChecked($hWndFrom, $a_hItem[$i][0])
                        If $a_hItem[$i][$a_hItem[0][1] + 1] <> $a_hItem[$i][$a_hItem[0][1] + 2] Then
                            $a_hItem[$i][$a_hItem[0][1] + 1] = $a_hItem[$i][$a_hItem[0][1] + 2]
                            For $j = 1 To $a_hItem[0][1]
                                If $a_hItem[$i][$j] Then
                                    _GUICtrlTreeView_SetChecked($hWndFrom, $a_hItem[$i][$j], $a_hItem[$i][$a_hItem[0][1] + 1])
                                EndIf
                            Next
                        EndIf
                    Next
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

При составлении дерева он не учитывает половину записей из ИНИ. Помогите найти ошибку :'(
Сам ИНИ прикреплен.
:IL_AutoIt_1:
 

Redline

AutoIT Гуру
Сообщения
506
Репутация
375
Код:
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Array.au3>

Global $sIniFile = @ScriptDir & '\test.ini'
$aParams = IniReadSection($sIniFile, "Arhives")
Global $iTotalParams = UBound($aParams) - 1
Global $Progs[$iTotalParams + 1]

$aParams2 = IniReadSection($sIniFile, "Test")
Global $iTotalParams2 = UBound($aParams2) - 1
Global $Progs2[$iTotalParams2 + 1]

Dim $a_hItem[$iTotalParams + 1][$iTotalParams2 + 3] = [[$iTotalParams, $iTotalParams2]]

$iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, _
		$TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)


$hGUI = GUICreate('Test', 400, 300, -1, -1, -1, $WS_CLIPCHILDREN)
$nButton = GUICtrlCreateButton('Click me', 150, 260, 100, 30)
$hTreeView = _GUICtrlTreeView_Create($hGUI, 2, 2, 396, 250, $iStyle, $WS_EX_CLIENTEDGE)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')


_GUICtrlTreeView_BeginUpdate($hTreeView)
For $i = 1 To $iTotalParams

	$aData = IniRead($sIniFile, "Arhives", "Arhives" & $i, "")

	$a_hItem[$i][0] = _GUICtrlTreeView_Add($hTreeView, 0, $aData)

	For $j = 1 To $iTotalParams2
		$parse = StringRegExp(IniRead($sIniFile, "Test", "test" & $j, "<?><de.exe><INI file ?><0>"), "<(.*?)>", 3)
		If $parse[3] = $aData Then
			$a_hItem[$i][$j] = _GUICtrlTreeView_AddChild($hTreeView, $a_hItem[$i][0], $parse[1])
			ExitLoop
		EndIf
	Next
	$a_hItem[$i][$a_hItem[0][1] + 2] = True
Next

_GUICtrlTreeView_EndUpdate($hTreeView)




While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $nButton
			$iCount = 0
			Dim $aData[1][2]
			For $i = 1 To $a_hItem[0][0]
				For $j = 1 To $a_hItem[0][1]
					If $a_hItem[$i][$j] Then
						If _GUICtrlTreeView_GetChecked($hTreeView, $a_hItem[$i][$j]) Then
							$iCount += 1
							ReDim $aData[$iCount + 1][2]
							$aData[$iCount][0] = _GUICtrlTreeView_GetText($hTreeView, $a_hItem[$i][0])
							$aData[$iCount][1] = _GUICtrlTreeView_GetText($hTreeView, $a_hItem[$i][$j])
						EndIf
					EndIf
				Next
			Next
			If $iCount Then
				$aData[0][0] = $iCount
				_ArrayDisplay($aData)
				;здесь делайте с отмеченными Item то, что Вам надо.
			Else
				MsgBox(16, 'Error', 'Нет отмеченных')
			EndIf
	EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
	#forceref $hWnd, $iMsg, $iwParam
	Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $fChecked
	$hWndTreeview = $hTreeView
	If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)
	$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
	$hWndFrom = HWnd(DllStructGetData($tNMHDR, 'hWndFrom'))
	$iCode = DllStructGetData($tNMHDR, 'Code')
	Switch $hWndFrom
		Case $hWndTreeview
			Switch $iCode
				Case $NM_CUSTOMDRAW
					For $i = 1 To $a_hItem[0][0]
						$a_hItem[$i][$a_hItem[0][1] + 2] = _GUICtrlTreeView_GetChecked($hWndFrom, $a_hItem[$i][0])
						If $a_hItem[$i][$a_hItem[0][1] + 1] <> $a_hItem[$i][$a_hItem[0][1] + 2] Then
							$a_hItem[$i][$a_hItem[0][1] + 1] = $a_hItem[$i][$a_hItem[0][1] + 2]
							For $j = 1 To $a_hItem[0][1]
								If $a_hItem[$i][$j] Then
									_GUICtrlTreeView_SetChecked($hWndFrom, $a_hItem[$i][$j], $a_hItem[$i][$a_hItem[0][1] + 1])
								EndIf
							Next
						EndIf
					Next
					Return 0
			EndSwitch
	EndSwitch
	Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Код:
[Arhives]
Arhives1=1c8
Arhives2=1c9
Arhives3=1c10

[Test]
test1=<test><test1><test><1c8>
test2=<test><test2><test><1c9>
test3=<test><test3><test><1c10>

1. Намеренно или нет, но в ini последняя строка была такая: test2=<test><test><test><1c10>, из-за этого происходит дублирование ключей. Добавил внутрь второго тега цифры, для удобства.
2. Подправил цикл (подсвечены ключевые строки) - раньше при отсутствии ключевого слова, например, 1с9 в первой строке test1= цикл обрывался и дальнейшего обхода по test2 test3 не происходило.
 

gregaz

AutoIT Гуру
Сообщения
1,166
Репутация
299
Centrinar [?]
Необходимо дерево в котором есть папки all и 1С и в них файл arhiv1 и arhiv2 соответственно. В основном проблема возникает что бы возле каждого элемента была возможность поставить ЧЕКБОКС

Приблизительно так :
Код:
; Содержание ИНИ файла
#cs
[all]
arhiv1=Temp1.rar
arhiv2=Temp2.rar
arhiv3=Temp3.rar
[1C]
arhiv1=test1.rar
arhiv2=test2.rar
arhiv3=test3.rar
#ce

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>

$Check=False
$sIniFile=@ScriptDir & "\Temp.Ini"

$hForm = GUICreate('Test',500, 400)
GUISetBkColor(0xECE9D8)

$hTreeView=_GUICtrlTreeView_Create($hForm, 5, 5, 490, 365,  $TVS_CHECKBOXES)

$ButTest=GUICtrlCreateButton('Test',450, 375, 40, 20);, $BS_ICON

GUIRegisterMsg($WM_NOTIFY, "_TV_WM_NOTIFY")
GUISetState()

TV_Update($hTreeView, $sIniFile)

While 1
	$nMsg = GUIGetMsg()
	
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $ButTest
			 ;......
	EndSwitch
WEnd


Func Click($hTV, $hItemTV)
    $fCheck=_GUICtrlTreeView_GetChecked($hTV, $hItemTV)
    $hChild = _GUICtrlTreeView_GetFirstChild($hTV, $hItemTV)
    _GUICtrlTreeView_SetChecked($hTV,$hChild, Not $fCheck)
    While  $hChild
        $hChild=_GUICtrlTreeView_GetNextChild($hTV,$hChild)
        If  $hChild Then  _GUICtrlTreeView_SetChecked($hTV,$hChild, Not $fCheck)
   WEnd
EndFunc

Func TV_Update($hTV, $sIni)
    $aSect=IniReadSectionNames ( $sIni)
    For $i=1 To UBound($aSect)-1
       $hParent=_GUICtrlTreeView_Add($hTV, 0, $aSect[$i])
       $aParam=IniReadSection ( $sIni, $aSect[$i])
        For $j=1 To UBound($aParam, 1)-1
            _GUICtrlTreeView_AddChild($hTV, $hParent, $aParam[$j][0])
        Next
    Next
    _GUICtrlTreeView_Expand($hTV)
EndFunc

Func _TV_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
	#forceref $hWnd, $iMsg, $iwParam
	Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview
	
	$hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

	$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
	$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
	$iCode = DllStructGetData($tNMHDR, "Code")
	
    Switch $hWndFrom
        Case 	$hWndTreeview
            Switch $iCode
                Case $NM_CLICK
                    $hClickedItemTV=_TV_GetItemHandle1($hWndFrom)
                    If $hClickedItemTV Then Click($hWndFrom, $hClickedItemTV)
                    ConsoleWrite ("$hClickedItemTV= " &$hClickedItemTV & @LF)
           EndSwitch
    EndSwitch

	Return $GUI_RUNDEFMSG
EndFunc	;==> WM_NOTIFY

Func _TV_GetItemHandle1($hTV)
  $tPoint = _WinAPI_GetMousePos(1, $hTV)
  If DllStructGetData($tPoint, "X") > 20 Then Return 0
  $tTVHTI = _GUICtrlTreeView_HitTestEx($hTV, DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2))
  $hItem = DllStructGetData($tTVHTI, 'Item')
  Return $hItem
EndFunc
Кнопку наверное сам сделаешь
 

kaster

Мой Аватар, он лучший самый
Команда форума
Глобальный модератор
Сообщения
4,020
Репутация
626
зачем создавать еще одну тему?
 

gregaz

AutoIT Гуру
Сообщения
1,166
Репутация
299
gregaz [?]
Кнопку наверное сам сделаешь

Да собственно и кнопка :
Код:
;.........................
Case $ButTest
 RunChecked($sIniFile, $hTreeView)
;........................

Func RunChecked($sIni, $hTV)
    $iCount=_GUICtrlTreeView_GetCount($hTV)
    For $i=1 To  $iCount
        If $i=1 Then 
            $hItem=_GUICtrlTreeView_GetFirstItem($hTV)
        Else
            $hItem= _GUICtrlTreeView_GetNext($hTV, $hItem)
        EndIf
        If _GUICtrlTreeView_GetChecked($hTV, $hItem) Then 
            $hParrent=_GUICtrlTreeView_GetParentHandle($hTV, $hItem )
            $sText=_GUICtrlTreeView_GetText($hTV, $hItem)
            $sTextParrent=_GUICtrlTreeView_GetText($hTV, $hParrent)
            $sFile=IniRead($sIni, $sTextParrent, $sText,'')
            If $sFile Then  ConsoleWrite ("$sFile = " & $sFile  & @LF);;;;;;; Любое действие с файлом
        EndIf
    Next
EndFunc
 

gregaz

AutoIT Гуру
Сообщения
1,166
Репутация
299
Оказывается все сильно упрощается , если использовать штатную ф-ию создания TreeView :
Можно отказаться и от WM_NOTIFY

Код:
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>

$Check=False
$sIniFile=@ScriptDir & "\Temp.Ini"

$hForm = GUICreate('Test',500, 400)
GUISetBkColor(0xECE9D8)

$hTreeView=GUICtrlCreateTreeView (5, 5, 490, 365,  $TVS_CHECKBOXES)
$ButTest=GUICtrlCreateButton('Test',450, 375, 40, 20);, $BS_ICON

GUISetState()
TV_Update($hTreeView, $sIniFile)

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $GUI_EVENT_PRIMARYDOWN
			$aArray= GUIGetCursorInfo ($hForm)
			If $aArray[4] <> $hTreeView Then ContinueLoop
			$hClickedItemTV=_TV_GetItemHandle1(ControlGetHandle ( $hForm, "", $hTreeView))
			If $hClickedItemTV Then Click($hTreeView, $hClickedItemTV)
		Case $ButTest
			RunChecked($sIniFile, $hTreeView)
	EndSwitch
WEnd

Func RunChecked($sIni, $hTV)
    $iCount=_GUICtrlTreeView_GetCount($hTV)
    For $i=1 To  $iCount
        If $i=1 Then 
            $hItem=_GUICtrlTreeView_GetFirstItem($hTV)
        Else
            $hItem= _GUICtrlTreeView_GetNext($hTV, $hItem)
        EndIf
        If _GUICtrlTreeView_GetChecked($hTV, $hItem) Then 
            $hParrent=_GUICtrlTreeView_GetParentHandle($hTV, $hItem )
            $sText=_GUICtrlTreeView_GetText($hTV, $hItem)
            $sTextParrent=_GUICtrlTreeView_GetText($hTV, $hParrent)
            $sFile=IniRead($sIni, $sTextParrent, $sText,'')
            If $sFile Then  ConsoleWrite ("$sFile = " & $sFile  & @LF);;;;;;; Любое действие с файлом
        EndIf
    Next
EndFunc

Func Click($hTV, $hItemTV)
    $fCheck=_GUICtrlTreeView_GetChecked($hTV, $hItemTV)
    $hChild = _GUICtrlTreeView_GetFirstChild($hTV, $hItemTV)
    _GUICtrlTreeView_SetChecked($hTV,$hChild, $fCheck)
    While  $hChild
        $hChild=_GUICtrlTreeView_GetNextChild($hTV,$hChild)
        If  $hChild Then  _GUICtrlTreeView_SetChecked($hTV,$hChild, $fCheck)
   WEnd
EndFunc

Func TV_Update($hTV, $sIni)
    $aSect=IniReadSectionNames ( $sIni)
    For $i=1 To UBound($aSect)-1
       $hParent=_GUICtrlTreeView_Add($hTV, 0, $aSect[$i])
       $aParam=IniReadSection ( $sIni, $aSect[$i])
        For $j=1 To UBound($aParam, 1)-1
            _GUICtrlTreeView_AddChild($hTV, $hParent, $aParam[$j][0])
        Next
    Next
    _GUICtrlTreeView_Expand($hTV)
EndFunc

Func _TV_GetItemHandle1($hTV)
  $tPoint = _WinAPI_GetMousePos(1, $hTV)
 ; If DllStructGetData($tPoint, "X") > 20 Then Return 0
  $tTVHTI = _GUICtrlTreeView_HitTestEx($hTV, DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2))
  $hItem = DllStructGetData($tTVHTI, 'Item')
  Return $hItem
EndFunc
 

Pelerin

Осваивающий
Сообщения
81
Репутация
23
Всем привет!
Я вот тут кое чего наваял по сабжу:
Код:
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiTreeView.au3>
#include <Array.au3>
$ini='test.ini'

GUICreate(@ScriptName, 400, 400)
$treeview=GUICtrlCreateTreeView(5, 5, 390, 365, $TVS_CHECKBOXES+$TVS_LINESATROOT+$TVS_HASLINES+$TVS_HASBUTTONS, $WS_EX_CLIENTEDGE)
$button=GUICtrlCreateButton("Кнопка", 5, 375, 390, 25)

$sect_name=IniReadSectionNames($ini)
Dim $tvi[1][$sect_name[0]+1][2]

For $i = 1 To $sect_name[0]
	$tvi[0][$i][0] = GUICtrlCreateTreeViewItem($sect_name[$i], $treeview)
	$sect= IniReadSection($ini, $sect_name[$i])
	For $ii = 1 To $sect[0][0]
		If $ii>$tvi[0][0][0] Then
			ReDim $tvi[$ii+1][$sect_name[0]+1][2]
			$tvi[0][0][0]+=1
		EndIf
		$tvi[$ii][$i][0]=GUICtrlCreateTreeViewItem($sect[$ii][0], $tvi[0][$i][0])
		$tvi[$ii][$i][1]=$sect[$ii][1]
	Next
Next

GUISetState()
Do
	$msg = GUIGetMsg()
	For $i = 1 To $sect_name[0]
		If $msg = $tvi[0][$i][0] Then
			For $ii = 1 To $tvi[0][0][0]
				GUICtrlSetState($tvi[$ii][$i][0], GUICtrlRead($tvi[0][$i][0]))
			Next
		EndIf
	Next
	If $msg = $button Then
		For $i = 1 To $sect_name[0]
			For $ii = 1 To $tvi[0][0][0]
				If _GUICtrlTreeView_GetChecked($treeview, $tvi[$ii][$i][0]) And $tvi[$ii][$i][1]<>'' Then
					ConsoleWrite('Запускаю ' &$tvi[$ii][$i][1]&@CRLF)
				EndIf
			Next
		Next
	EndIf
Until $msg = $gui_event_close
Немного по другому. Но вроде работает.. Кто что думает?


Добавлено:
Сообщение автоматически объединено:

Если есть вопросы по коду выше - задавайте.
 
Верх