Hi,
Ich möchte ein Programm schreiben in dem am ende eine INI datei mit den einstellungen ausgeworfen wird. Der benutzer bekommt eine GUI in der nur eine Treeview und 2 Bilder drinne sind. Mehr nicht. Der Benutzer soll nun den Treeview gestalten, er legt sozusagen Folder an und in die Folder dann, über Kontextmenüe -> Dropdown Items.
Die Items kommen aus einer Vorlage. zb
Sessions.txt Inhalt (Jede Zeile ist ein Item):
https://autoit.de/www.google.de
c:/Documentationen\
Hostname1
Hostname2
FTP-Session1
"Mein Gott was weiß ich"
So. Das zum Ablauf des Programms.
Aus der Suche über Google und AutoIT suche kommt nicht grade viel bei raus.
Treeview mit Checkbox nett aber hilft mir nicht.
Spoiler anzeigen
#include<GUIConstantsEx.au3>
#include<GuiTreeView.au3>
#include<TreeViewConstants.au3>
#include<WindowsConstants.au3>
Global $hGui = GUICreate('TreeView-(Un)Checked-Example', 400, 600)
Global $hTreeView = GUICtrlCreateTreeView(5, 5, 390, 590, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE)
Global $hRoot = GUICtrlCreateTreeViewItem('Root', $hTreeView)
_GUICtrlTreeView_SetBold($hTreeView, $hRoot)
_GUICtrlTreeView_BeginUpdate($hTreeView)
For $x = 1 To 3
$hItem1 = _GUICtrlTreeView_AddChild($hTreeView, GUICtrlGetHandle($hRoot), StringFormat('[d] Child 1st Gen.', $x))
For $y = 1 To 3
$hItem2 = _GUICtrlTreeView_AddChild($hTreeView, $hItem1, StringFormat('[d] Child 2nd Gen.', $y))
For $z = 1 To 2
$hItem3 = _GUICtrlTreeView_AddChild($hTreeView, $hItem2, StringFormat('[d] Child 3rd Gen.', $z))
Next
Next
Next
_GUICtrlTreeView_EndUpdate($hTreeView)
_GUICtrlTreeView_Expand($hTreeView)
GUISetState()
While True
Switch GUIGetMsg()
Case $GUI_EVENT_PRIMARYDOWN ; (*)
$aInfo = GUIGetCursorInfo($hGui) ; (*)
If $aInfo[4] = $hTreeView Then ; (*)
$aAdjust = ControlGetPos($hGui, '', $hTreeView) ; (*)
If BitAND(_GUICtrlTreeView_HitTest($hTreeView, $aInfo[0]-$aAdjust[0]-2, $aInfo[1]-$aAdjust[1]-2), 64) Then ; (*)
$hSelect = _GUICtrlTreeView_GetSelection($hTreeView)
$checked = _GUICtrlTreeView_GetChecked($hTreeView, $hSelect)
$hItem = _GUICtrlTreeView_GetFirstChild($hTreeView, $hSelect)
If $hItem Then _SetChildItemsChecked($hTreeView, $hItem, $checked)
If $checked Then
_VerifySiblingItems($hTreeView, $hSelect)
Else
_SetParentItemsUnchecked($hTreeView, $hSelect)
EndIf
EndIf
EndIf
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
; (*) = diese Konstruktion ist notwendig, weil man sonst nicht zwischen einem Mausklick
; auf den Item-Text und der Checkbox unterscheiden kann
; Überprüft (rekursiv) ob alle Sibling-Items angehakt sind und setzt, wenn zutreffend, den Haken beim Parent-Item
Func _VerifySiblingItems($hTreeView, $hItem)
Local $hTmp, $hSave = $hItem, $iCount = _GUICtrlTreeView_GetSiblingCount($hTreeView, $hItem)
While True
$hTmp = _GUICtrlTreeView_GetNextSibling($hTreeView, $hItem)
If Not $hTmp Then ExitLoop
$hItem = $hTmp
WEnd
Do
If _GUICtrlTreeView_GetChecked($hTreeView, $hItem) Then $iCount -= 1
$hItem = _GUICtrlTreeView_GetPrevSibling($hTreeView, $hItem)
Until Not $hItem
If Not $iCount Then
Local $hParent = _GUICtrlTreeView_GetParentHandle($hTreeView, $hSave)
If $hParent Then
_GUICtrlTreeView_SetChecked($hTreeView, $hParent)
_VerifySiblingItems($hTreeView, $hParent)
EndIf
EndIf
EndFunc
; Setzt (rekursiv) den Haken bei allen Child-Items, wenn der Haken bei einem Item gesetzt wurde
Func _SetChildItemsChecked($hTreeView, $hItem, $checked)
Do
Local $hNewItem = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem)
If $hNewItem Then _SetChildItemsChecked($hTreeView, $hNewItem, $checked)
_GUICtrlTreeView_SetChecked($hTreeView, $hItem, $checked)
$hItem = _GUICtrlTreeView_GetNextChild($hTreeView, $hItem)
Until Not $hItem
EndFunc
; Entfernt (rekursiv) den Haken bei allen Parents, wenn der Haken von einem Item entfernt wurde
Func _SetParentItemsUnchecked($hTreeView, $hItem)
Local $hParent = _GUICtrlTreeView_GetParentHandle($hTreeView, $hItem)
If $hParent Then _SetParentItemsUnchecked($hTreeView, $hParent)
_GUICtrlTreeView_SetChecked($hTreeView, $hItem, False)
EndFunc
Treeview das mit ein Explorer darstellt. Nett hilft mir leider auch nicht.
Spoiler anzeigen
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiTreeView.au3>
#include <StructureConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
[/autoit] [autoit][/autoit] [autoit]Global $hGui = GUICreate('FileExplorer', 400, 400)
[/autoit] [autoit][/autoit] [autoit]Global Const $Delim = '\', $Delim1 = '|'
[/autoit] [autoit][/autoit] [autoit]Global $hTreeview = GUICtrlCreateTreeView(10, 10, 380, 360)
Global $hWndTreeview = GUICtrlGetHandle($hTreeview)
Global $hOk = GUICtrlCreateButton('Ok', 240, 375, 60, 22)
Global $hCancel = GUICtrlCreateButton('Cancel', 320, 375, 60, 22)
Global $hImage = _GUIImageList_Create(16, 16, 5, 1)
_GUIImageList_AddIcon($hImage, 'shell32.dll', 3) ; Verzeichnis-Icon
_GUIImageList_AddIcon($hImage, 'shell32.dll', 110) ; Verzeichnis-Icon mit Haken
_GUIImageList_AddIcon($hImage, 'shell32.dll', 1) ; Datei-Icon
_GUIImageList_AddIcon($hImage, 'shell32.dll', 5) ; Diskette
_GUIImageList_AddIcon($hImage, 'shell32.dll', 7) ; Wechseldatenträger
_GUIImageList_AddIcon($hImage, 'shell32.dll', ; Festplatte
_GUIImageList_AddIcon($hImage, 'shell32.dll', 11) ; CDROM
_GUIImageList_AddIcon($hImage, 'shell32.dll', 12) ; Netzwerklaufwerk
_GUIImageList_AddIcon($hImage, 'shell32.dll', 53) ; Unbekannt
_GUICtrlTreeView_SetNormalImageList($hTreeview, $hImage)
GUISetState()
GUICtrlSetStyle($hTreeview, Default, BitOR($WS_EX_COMPOSITED, $WS_EX_CLIENTEDGE))
If ToolTip('Please wait...', Default, Default, 'Read Directory', 1) Then Local $aDrives = DriveGetDrive('ALL'), $iLWindex, $hRoot
For $i = 1 To $aDrives[0]
$iLWindex = 0
Switch DriveGetType($aDrives[$i])
Case 'Fixed'
$iLWindex = 5
Case 'CDROM'
$iLWindex = 6
Case 'RAMDisk'
$iLWindex = 7
Case 'Removable'
$iLWindex = 4
If StringLeft($aDrives[$i], 2) = 'a:' Or StringLeft($aDrives[$i], 2) = 'b:' Then $iLWindex = 3
Case Else
$iLWindex = 8
EndSwitch
$hRoot = _GUICtrlTreeView_Add($hTreeview, $hTreeview, StringUpper($aDrives[$i]), $iLWindex, $iLWindex)
If DriveStatus($aDrives[$i]) <> 'READY' Then ContinueLoop
If _GUICtrlTreeView_BeginUpdate($hTreeview) And _GUICtrlTreeView_FileExplorer($hTreeview, $hRoot, $aDrives[$i]) Then _GUICtrlTreeView_EndUpdate($hTreeview)
Next
ToolTip('')
GUIRegisterMsg($WM_NOTIFY, '_WM_NOTIFY')
While True
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $hCancel
Exit
Case $hOk
MsgBox(0, 'Selected Path/File', StringReplace(_GUICtrlTreeView_GetTree($hTreeview, _GUICtrlTreeView_GetSelection($hTreeview)), $Delim1, $Delim))
EndSwitch
WEnd
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hChild, $hITEM, $tNMTREEVIEW = DllStructCreate($tagNMTREEVIEW, $ilParam)
If DllStructGetData($tNMTREEVIEW, 'hWndFrom') = $hWndTreeview Then
Switch DllStructGetData($tNMTREEVIEW, 'Code')
Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
Switch DllStructGetData($tNMTREEVIEW, 'Action')
Case $TVE_EXPAND
If ToolTip('Please wait...', Default, Default, 'Read Directory', 1) Then $hITEM = DllStructGetData($tNMTREEVIEW, 'NewhItem')
If _GUICtrlTreeView_GetExpanded($hTreeview, $hITEM) Then Return $GUI_RUNDEFMSG
$hChild = _GUICtrlTreeView_GetFirstChild($hTreeview, $hITEM)
If Not $hChild Then Return $GUI_RUNDEFMSG
If _GUICtrlTreeView_BeginUpdate($hTreeview) Then _GUICtrlTreeView_DeleteChildren($hTreeview, $hChild)
_GUICtrlTreeView_FileExplorer($hTreeview, $hChild, StringReplace(_GUICtrlTreeView_GetTree($hTreeview, $hChild), $Delim1, $Delim))
Do
$hChild = _GUICtrlTreeView_GetNextChild($hTreeview, $hChild)
If Not $hChild Then ExitLoop
_GUICtrlTreeView_DeleteChildren($hTreeview, $hChild)
_GUICtrlTreeView_FileExplorer($hTreeview, $hChild, StringReplace(_GUICtrlTreeView_GetTree($hTreeview, $hChild), $Delim1, $Delim))
Until False
If _GUICtrlTreeView_EndUpdate($hTreeview) Then ToolTip('')
EndSwitch
EndSwitch
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_NOTIFY
Func _GUICtrlTreeView_FileExplorer($hTreeview, $hITEM, $sPath)
Local $sFileList, $sFolderList, $aDirList, $hSearch, $sFile
Local $iHidden = RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced', 'Hidden') - 1
Local $iSuperHidden = Not RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced', 'ShowSuperHidden')
$hSearch = FileFindFirstFile($sPath & $Delim & '*')
If $hSearch = -1 Then Return True
Do
$sFile = FileFindNextFile($hSearch)
If @error Then ExitLoop
Switch @extended
Case False
If $iHidden And StringInStr(FileGetAttrib($sPath & $Delim & $sFile), 'H') Then ContinueLoop
If $iSuperHidden And StringInStr(FileGetAttrib($sPath & $Delim & $sFile), 'S') Then ContinueLoop
$sFileList &= $sFile & $Delim1
Case True
If _IsReparsePoint($sPath & $Delim & $sFile) Then ContinueLoop
$sFolderList &= $sFile & $Delim1
EndSwitch
Until False
FileClose($hSearch)
If $sFolderList & $sFileList = '' Then Return True
$aDirList = StringSplit(StringTrimRight($sFolderList & $sFileList, 1), $Delim1, 2)
For $sFile In $aDirList
If StringInStr(FileGetAttrib($sPath & $Delim & $sFile), 'D') Then
_GUICtrlTreeView_AddChild($hTreeview, $hITEM, $sFile, 0, 1)
Else
_GUICtrlTreeView_AddChild($hTreeview, $hITEM, $sFile, 2, 2)
EndIf
Next
Return True
EndFunc ;==>_GUICtrlTreeView_FileExplorer
Func _IsReparsePoint($FLS) ; progandy
Dim Static $K32 = DllOpen('kernel32.dll')
Dim $DA = DllCall($K32, 'dword', 'GetFileAttributesW', 'wstr', $FLS)
If @error Then Return SetError(1, @error, False)
Return BitAND($DA[0], 1024) = 1024
EndFunc ;==>_IsReparsePoint
Könnt ihr mir Helfen? Ich brauch Eine Treeview in der man Folder und Items anlegen kann. Items werden aus einem Dropdown (vordefiniert) oder extra zusätzlich eingetragen über ein Inputfeld. Das man über ein Kontextmenüe erreichen kann. Wie bau ich da pro Term ein Kontextmenü drann? Jede änderung soll gleich in die InI geschrieben werden. Wie programire ich das so? Ich habe bisher immer nur mit Button "Speichern" gearbeitet. Wo man zum Schluss alles Speichert. Habe also Keine erfahrung mit so einem Luxus
Normal ließt er die Ini wenn vorhanden ein beim Starten. Dann stellt er was dar. Wenn ich da was ändere soll es mit geändert werden. Finde das ist schwer. Normal hab ich die alte datei einfach gelöscht und neu erstellt. Breuchte also ne art wegweißer dazu.
Mal sehen was zusammen kommt. Danke