Sign in to follow this  
Followers 0
Rex

get name of item in treeview

4 posts in this topic

:P

Hi i do have one big prob. with this damnd script.

; Generated by NewScript 4.5
#include <GUIConstants.au3>; Includes GUIConstants.au3 to script
#include <file.au3>
; Opt's Start > --------------------------------------------------------------
; Opt("RunErrorsFatal", 1)     ;1=fatal, 0=silent set @error
; Opt("GUIOnEventMode", 0)     ;0=disabled, 1=OnEvent mode enabled
; Opt("GUICloseOnESC", 1)       ;1=ESC  closes, 0=ESC won't close
; Opt("TrayIconDebug", 0)       ;0=no info, 1=debug line info
; Opt("TrayMenuMode",0)       ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID  not return
; Opt("TrayOnEventMode",0)     ;0=disable, 1=enable
; Opt("TrayIconHide", 0)         ;0=show, 1=hide tray icon
; Opt("TrayAutoPause",1)         ;0=no pause, 1=Pause
; Opt's End > ----------------------------------------------------------------
; Script start

Global $ahsLines[1][2], $TmpFile, $i, $Filename

$Utility_Launcher = GUICreate(" Utility Launcher", 362, 206, 193, 126, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUPWINDOW,$WS_BORDER))
GUICtrlCreateLabel("", 16, 16, 4, 4)
GUICtrlCreateLabel("Please choose ulility to launch", 16, 16, 328, 28, $SS_CENTER)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$Add_Utility = GUICtrlCreateButton("&Add", 192, 168, 75, 25, 0)
GUICtrlSetTip(-1, "Adds a Utility to Launce")
$Launch = GUICtrlCreateButton("&Launch", 16, 168, 75, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetTip(-1, "Launchec Selected Utility")
$Exits = GUICtrlCreateButton("&Exit", 96, 168, 75, 25, 0)
GUICtrlSetTip(-1, "Exits Launcher")
$Utilitys_to_Launch = GUICtrlCreateTreeView(16, 40, 329, 113, BitOR($TVS_CHECKBOXES,$WS_BORDER), 0)
$Remove_Utility = GUICtrlCreateButton("&Remove", 272, 168, 75, 25, 0)
GUICtrlSetTip(-1, "Removes selceted Utility")
GUISetState(@SW_SHOW)

_Readline(); Reloads ini file into treeview

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Add_Utility
            
            $BF = 0
    $TmpFile = FileOpenDialog("Utility to add", @ScriptDir, "Exe files (*.exe)", 3); 
        Dim $szDrive, $szDir, $szFName, $szExt
_PathSplit($TmpFile, $szDrive, $szDir, $szFName, $szExt); Retives only the file name (we do not need the path, course files must be inside the scriptDir)
$Filename = $szFName & $szExt
;MsgBox(0, "Check 1", $szFName & $szExt)
        _AddItem()
        
        Case $Launch
            
            $Read1 = GUICtrlRead($Utilitys_to_Launch)
            MsgBox(0, "read", $Read1)
            If $Read1 <> "" Then
            ;Run(@ScriptDir & "\" & $Read1); Damned thing dont work :(
            EndIf
            Exit
        Case $Exits
            Exit
        Case $Remove_Utility
            _DeleteItem()
    EndSwitch
WEnd

Func _Addline()
    $i = 1
    $Lines = _FileCountLines(@ScriptDir & "\" & "Config.ini")
    ReDim $ahsLines[$Lines][2]
    $file = FileOpen(@ScriptDir & "\" & "Config.ini", 0)
    
    Do
        $i = $lines
    $line = FileReadLine($file, $i)
    $ahsLines[$i-1][0] = $line
    $ahsLines[$i-1][1] = GuiCtrlCreateTreeViewItem($line, $Utilitys_to_Launch)
Until $i = $lines

FileClose($file)
EndFunc


Func _AddItem()
    FileWriteLine(@ScriptDir & "\" & "Config.ini", $Filename)
    $TmpFile = ""; Clears Tmp file
        FileCopy(@ScriptDir & "\" & "Config.ini", @ScriptDir & "\" & "Config.tmp", 1)
_Addline()
EndFunc

Func _Readline()
    
    $i = 0
    $Lines = _FileCountLines(@ScriptDir & "\" & "Config.ini")
    
    If Not $lines = 0 Then
    ReDim $ahsLines[$Lines][2]
    
    $file = FileOpen(@ScriptDir & "\" & "Config.ini", 0)
        
    Do
        $i = $i + 1
    $line = FileReadLine($file, $i)
    $ahsLines[$i-1][0] = $line
    $ahsLines[$i-1][1] = GuiCtrlCreateTreeViewItem($line, $Utilitys_to_Launch)
    
Until $i = $lines

FileClose($file)

EndIf
EndFunc
Func _DeleteItem()
    $read = GUICtrlRead($Utilitys_to_Launch)
    if $Read = 0 Then
        MsgBox(64, "Delete Item", "Nothing to delete, list is empty or item not checked")
    EndIf
    FileDelete(@ScriptDir & "\" & "Config.tmp")     
        For $i = 0 To UBound($ahsLines) - 1
            If BitAnd(GUICtrlRead($ahsLines[$i][1]), 1) Then 
                GUICtrlDelete($ahsLines[$i][1])
                $ahsLines[$i][1] = 0
                If Not FileExists(@ScriptDir & "\" & "Config.tmp") Then; 
                    FileDelete(@ScriptDir & "\" & "Config.ini")
                    FileWrite(@ScriptDir & "\" & "Config.ini", "")
                    FileWrite(@ScriptDir & "\" & "Config.tmp", "")
                    EndIf
                ContinueLoop
            Endif
            
            If $ahsLines[$i][1] Then FileWriteLine(@ScriptDir & "\" & "Config.tmp", $ahsLines[$i][0])
                FileCopy(@ScriptDir & "\" & "Config.tmp", @ScriptDir & "\" & "Config.ini", 1)
            Next
        EndFunc

I can't get the name of the selected treeview item, only the state 10, 11, 12 ect. did try to concole helpfile put no help for me there Posted Image can any of you help me ???

/Rex

Share this post


Link to post
Share on other sites



Hi,

I know that doen't help you, but why are you doing that with treeviewitems insted of checkboxes?

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@th.meger I think the reason is because the script is creating a dynamic list. It is easier to add a text to the TreeView than recreating the entier GUI to add another checkbox.

Rex Give it a try...

; Generated by NewScript 4.5
#include <GUIConstants.au3>; Includes GUIConstants.au3 to script
#include <file.au3>
; Opt's Start > --------------------------------------------------------------
; Opt("RunErrorsFatal", 1)       ;1=fatal, 0=silent set @error
; Opt("GUIOnEventMode", 0)       ;0=disabled, 1=OnEvent mode enabled
; Opt("GUICloseOnESC", 1)        ;1=ESC  closes, 0=ESC won't close
; Opt("TrayIconDebug", 0)        ;0=no info, 1=debug line info
; Opt("TrayMenuMode",0)          ;0=append, 1=no default menu, 2=no automatic check, 4=menuitemID  not return
; Opt("TrayOnEventMode",0)       ;0=disable, 1=enable
; Opt("TrayIconHide", 0)         ;0=show, 1=hide tray icon
; Opt("TrayAutoPause",1)         ;0=no pause, 1=Pause
; Opt's End > ----------------------------------------------------------------
; Script start

Global $ahsLines[1][2], $TmpFile, $i, $Filename

$Utility_Launcher = GUICreate(" Utility Launcher", 362, 206, 193, 126, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUPWINDOW,$WS_BORDER))
GUICtrlCreateLabel("", 16, 16, 4, 4)
GUICtrlCreateLabel("Please choose ulility to launch", 16, 16, 328, 28, $SS_CENTER)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x0000FF)
$Add_Utility = GUICtrlCreateButton("&Add", 192, 168, 75, 25, 0)
GUICtrlSetTip(-1, "Adds a Utility to Launce")
$Launch = GUICtrlCreateButton("&Launch", 16, 168, 75, 25, $BS_DEFPUSHBUTTON)
GUICtrlSetTip(-1, "Launchec Selected Utility")
$Exits = GUICtrlCreateButton("&Exit", 96, 168, 75, 25, 0)
GUICtrlSetTip(-1, "Exits Launcher")
$Utilitys_to_Launch = GUICtrlCreateTreeView(16, 40, 329, 113, BitOR($TVS_CHECKBOXES,$WS_BORDER), 0)
$Remove_Utility = GUICtrlCreateButton("&Remove", 272, 168, 75, 25, 0)
GUICtrlSetTip(-1, "Removes selceted Utility")
GUISetState(@SW_SHOW)

_Readline(); Reloads ini file into treeview

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Add_Utility
            
            $BF = 0
    $TmpFile = FileOpenDialog("Utility to add", @ScriptDir, "Exe files (*.exe)", 3); 
        Dim $szDrive, $szDir, $szFName, $szExt
_PathSplit($TmpFile, $szDrive, $szDir, $szFName, $szExt); Retives only the file name (we do not need the path, course files must be inside the scriptDir)
$Filename = $szFName & $szExt
;MsgBox(0, "Check 1", $szFName & $szExt)
        _AddItem()
        
    Case $Launch
            For $x = 0 To UBound($ahsLines) - 1                             
                If BitAND(GUICtrlRead($ahsLines[$x][1]), $GUI_CHECKED) Then 
                    MsgBox(0, "read", $ahsLines[$x][0])
                    ;Run(@ScriptDir & "\" & $ahsLines[$x][0]); Damned thing dont work :(
                EndIf
            Next                              
        Case $Exits
            Exit
        Case $Remove_Utility
            _DeleteItem()
    EndSwitch
WEnd

Func _Addline()
    $i = 1
    $Lines = _FileCountLines(@ScriptDir & "\" & "Config.ini")
    ReDim $ahsLines[$Lines][2]
    $file = FileOpen(@ScriptDir & "\" & "Config.ini", 0)
    
    Do
        $i = $lines
    $line = FileReadLine($file, $i)
    $ahsLines[$i-1][0] = $line
    $ahsLines[$i-1][1] = GuiCtrlCreateTreeViewItem($line, $Utilitys_to_Launch)
Until $i = $lines

FileClose($file)
EndFunc


Func _AddItem()
    FileWriteLine(@ScriptDir & "\" & "Config.ini", $Filename)
    $TmpFile = ""; Clears Tmp file
        FileCopy(@ScriptDir & "\" & "Config.ini", @ScriptDir & "\" & "Config.tmp", 1)
_Addline()
EndFunc

Func _Readline()
    
    $i = 0
    $Lines = _FileCountLines(@ScriptDir & "\" & "Config.ini")
    
    If Not $lines = 0 Then
    ReDim $ahsLines[$Lines][2]
    
    $file = FileOpen(@ScriptDir & "\" & "Config.ini", 0)
        
    Do
        $i = $i + 1
    $line = FileReadLine($file, $i)
    $ahsLines[$i-1][0] = $line
    $ahsLines[$i-1][1] = GuiCtrlCreateTreeViewItem($line, $Utilitys_to_Launch)
    
Until $i = $lines

FileClose($file)

EndIf
EndFunc
Func _DeleteItem()
    $read = GUICtrlRead($Utilitys_to_Launch)
    if $Read = 0 Then
        MsgBox(64, "Delete Item", "Nothing to delete, list is empty or item not checked")
    EndIf
    FileDelete(@ScriptDir & "\" & "Config.tmp")        
        For $i = 0 To UBound($ahsLines) - 1
            If BitAnd(GUICtrlRead($ahsLines[$i][1]), 1) Then 
                GUICtrlDelete($ahsLines[$i][1])
                $ahsLines[$i][1] = 0
                If Not FileExists(@ScriptDir & "\" & "Config.tmp") Then; 
                    FileDelete(@ScriptDir & "\" & "Config.ini")
                    FileWrite(@ScriptDir & "\" & "Config.ini", "")
                    FileWrite(@ScriptDir & "\" & "Config.tmp", "")
                    EndIf
                ContinueLoop
            Endif
            
            If $ahsLines[$i][1] Then FileWriteLine(@ScriptDir & "\" & "Config.tmp", $ahsLines[$i][0])
                FileCopy(@ScriptDir & "\" & "Config.tmp", @ScriptDir & "\" & "Config.ini", 1)
            Next
        EndFunc

Note: you already have the information in your array $ahsLines

If you want to only run the first checked program, add ExitLoop after this line:

;Run(@ScriptDir & "\" & $ahsLines[$x][0]); Damned thing dont work :P

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

@th.meger I think the reason is because the script is creating a dynamic list. It is easier to add a text to the TreeView than recreating the entier GUI to add another checkbox.

True, i finde it simpler to add items to a checklist/treeview with use of a ini file then to rebuild a checkbox gui every time i want a new utility in my launcher :P

Rex Give it a try...

Did that, works like a charme :idea:

Note: you already have the information in your array $ahsLines

that was what i thought to, but i dont understand how thoes dam... array'rs woks, the ones i use in my script was kindly provided by Lazycat for a nother script i did try to make longe time ago :nuke:

If you want to only run the first checked program, add ExitLoop after this line:

;Run(@ScriptDir & "\" & $ahsLines[$x][0]); Damned thing dont work :D

Don that, was removed for testing

Thx Danny, you saved my day :lol::)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0