Jump to content

Can I get the control ID from a for loop?


Foy
 Share

Recommended Posts

Okay I got a neat lil program here...

I vote you make a test.ini on ur desktop so it works... lol

My real question is in

for $i = 1 to $sections[0]
    $currItem = GuiCtrlCreateTreeViewItem($sections[$i], $tree)
    GUICtrlSetColor(-1, 0x0000F0)
    GuiCtrlSetFont(-1, 9, 1000000)
    GuiCtrlSetState(-1, $GUI_DefButton)
    $value = IniReadSection($path, $sections[$i])
    $body &= "["&$sections[$i]&"]"
    for $m = 1 to $value[0][0]
        GuiCtrlCreateTreeViewItem($value[$m][0], $currItem)
        $body &= @CRLF&"    "&$value[$m][0]&" = "&$value[$m][1]
    next
    $body &= @CRLF
next

Can I get the control ID of each TreeViewItems?

I tried $data = GuiCtrlRead($tree, 1)

but I can't get it to register in the $msg = GuiGetMsg()...

It seems tricky for me, there's probably some simple answer, or none at all. :s

To further elaborate I need it so that when I click on the treeview list populated via for loop the key and value go to the input boxes.

Maybe there's a better way....

Btw, I need it from $path, as it'll be run via command, not via running it with one set .ini file. :\

Well thanks in advance if you can help, my whole is script is down hur:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.8.1
 Author:         FOY

 Script Function:
    Reads and edits Ini files.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiConstants.au3>


$GUI = GuiCreate("IniReader --- by Foy", 400, 270)
GuiSetState()
;$path = $cmdLine[1]
$path = @desktopdir&"\test.ini"
$sections = IniReadSectionNames($path)

$fileMenu = GuiCtrlCreateMenu("File")
$saveMen = GuiCtrlCreateMenuItem("Save Changes         (Ctrl+S)", $fileMenu)
$ResetMen = GuiCtrlCreateMenuItem("Undo All Changes    (Ctrl+Z)", $fileMenu)
$quitMen = GuiCtrlCreateMenuItem("Quit                              (Esc)", $fileMenu)
$HelpMenu = GuiCtrlCreateMenu("Help")
$AboutMen = GuiCtrlCreateMenuItem("About", $helpmenu)
$helpMen = GuiCtrlCreateMenuItem("Help", $helpmenu)
HotKeySet("{esc}", "ExitProg")
HotKeySet("^S", "Save")
HotKeySet("^Z", "Reset")
GUICtrlCreateLabel("", 0, 0, 500, 2, $SS_SUNKEN)
GuiCtrlCreateLabel("Key name:", 120, 80, 50, 15)
$key = GuiCtrlCreateInput("", 120, 100, 120, 20)
GuiCtrlSetState(-1, $Gui_Disable)
GuiCtrlCreateLabel("=", 245, 101, 15, 15)
GuiCtrlCreateLabel("Value:", 260, 80, 50, 15)
$val = GuiCtrlCreateInput("", 260, 100, 120, 20)
GuiCtrlSetState(-1, $Gui_Disable)
$button_Save = GuiCtrlCreateButton("Save", 125, 215, 80, 30)
$button_Reset = GuiCtrlCreateButton("Reset", 210, 215, 80, 30)
$button_Quit = GuiCtrlCreateButton("Quit", 295, 215, 80, 30)
$label_sectionNum = GuiCtrlCreateLabel("Number of sections: "&$sections[0], 20, 9, 150, 20)
$body = ""
$tree = GUICtrlCreateTreeView(5, 30, 100, 215, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
for $i = 1 to $sections[0]
    $currItem = GuiCtrlCreateTreeViewItem($sections[$i], $tree)
    GUICtrlSetColor(-1, 0x0000F0)
    GuiCtrlSetFont(-1, 9, 1000000)
    GuiCtrlSetState(-1, $GUI_DefButton)
    $value = IniReadSection($path, $sections[$i])
    $body &= "["&$sections[$i]&"]"
    for $m = 1 to $value[0][0]
        GuiCtrlCreateTreeViewItem($value[$m][0], $currItem)
        $body &= @CRLF&"    "&$value[$m][0]&" = "&$value[$m][1]
    next
    $body &= @CRLF
next
$spacer = GuiCtrlCreateTreeViewItem("", $tree)
GuiCtrlDelete($spacer)
msgbox(0, "", $tree)

func exitProg()
    Exit
endfunc

func save()
    
EndFunc

Func Sec1Val1()
    
EndFunc

func reset()
    for $i = 1 to $sections[0]
        $value = IniReadSection($path, $sections[$i])
        for $m = 1 to $value[0][0]
            
        next
    next
EndFunc

while 1
    $data = GuiCtrlRead($tree, 1)
    $msg = GUIGetMsg()
    Select
        case $msg = $GUI_EVENT_CLOSE OR $msg = $quitMen OR $msg = $button_quit
            exitprog()
        case $msg = $ResetMen OR $msg = $button_Reset
            reset()
        case $msg = $saveMen OR $msg = $button_Save
            save()
        case $msg = ; ????????? How to get this? O.O From the treeview item...
            msgbox(0, "", $data)
    EndSelect
WEnd
Edited by Foy
Link to comment
Share on other sites

I figured this would be not to hard if you used OnEventMode.

I moded the code to work for you. If you can't figure out how to do whatever else you want, I'd be happy to help :)

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.2.8.1
 Author:         FOY

 Script Function:
    Reads and edits Ini files.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <GuiConstants.au3>
#Include <GuiTreeView.au3>
HotKeySet("{esc}", "ExitProg")
HotKeySet("^S", "Save")
HotKeySet("^Z", "Reset")

Opt("GuiOnEventMode",1)

$GUI = GuiCreate("IniReader --- by Foy", 400, 270)
GuiSetState()
;$path = $cmdLine[1]
$path = @desktopdir&"\test.ini"
$sections = IniReadSectionNames($path)

$fileMenu = GuiCtrlCreateMenu("File")
$saveMen = GuiCtrlCreateMenuItem("Save Changes         (Ctrl+S)", $fileMenu)
$ResetMen = GuiCtrlCreateMenuItem("Undo All Changes    (Ctrl+Z)", $fileMenu)
$quitMen = GuiCtrlCreateMenuItem("Quit                              (Esc)", $fileMenu)
GUICtrlSetOnEvent(-1, "exitProg")
$HelpMenu = GuiCtrlCreateMenu("Help")
$AboutMen = GuiCtrlCreateMenuItem("About", $helpmenu)
$helpMen = GuiCtrlCreateMenuItem("Help", $helpmenu)

GUICtrlCreateLabel("", 0, 0, 500, 2, $SS_SUNKEN)
GuiCtrlCreateLabel("Key name:", 120, 80, 50, 15)
$key = GuiCtrlCreateInput("", 120, 100, 120, 20)
GuiCtrlSetState(-1, $Gui_Disable)
GuiCtrlCreateLabel("=", 245, 101, 15, 15)
GuiCtrlCreateLabel("Value:", 260, 80, 50, 15)
$val = GuiCtrlCreateInput("", 260, 100, 120, 20)
GuiCtrlSetState(-1, $Gui_Disable)
$button_Save = GuiCtrlCreateButton("Save", 125, 215, 80, 30)
GUICtrlSetOnEvent(-1, "save")
$button_Reset = GuiCtrlCreateButton("Reset", 210, 215, 80, 30)
GUICtrlSetOnEvent(-1, "reset")
$button_Quit = GuiCtrlCreateButton("Quit", 295, 215, 80, 30)
GUICtrlSetOnEvent(-1, "exitProg")
$label_sectionNum = GuiCtrlCreateLabel("Number of sections: "&$sections[0], 20, 9, 150, 20)
$body = ""
$tree = GUICtrlCreateTreeView(5, 30, 100, 215, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
for $i = 1 to $sections[0]
    $currItem = GuiCtrlCreateTreeViewItem($sections[$i], $tree)
    GUICtrlSetColor(-1, 0x0000F0)
    GuiCtrlSetFont(-1, 9, 1000000)
    GuiCtrlSetState(-1, $GUI_DefButton)
    $value = IniReadSection($path, $sections[$i])
    $body &= "["&$sections[$i]&"]"
    for $m = 1 to $value[0][0]
        $KeyItem = GuiCtrlCreateTreeViewItem($value[$m][0], $currItem)
        GUICtrlSetOnEvent($KeyItem, "Update")
        $body &= @CRLF&"    "&$value[$m][0]&" = "&$value[$m][1]
        
    next
    $body &= @CRLF
next
$spacer = GuiCtrlCreateTreeViewItem("", $tree)
GuiCtrlDelete($spacer)

while 1 
    sleep(100)
WEnd


func exitProg()
    Exit
endfunc

func save()
   
EndFunc

Func Sec1Val1()
   
EndFunc

func reset()
    for $i = 1 to $sections[0]
        $value = IniReadSection($path, $sections[$i])
        for $m = 1 to $value[0][0]
           
        next
    next
EndFunc


Func Update()
    $result= IniRead($Path,  _GUICtrlTreeViewGetText ($tree, _GUICtrlTreeViewGetParentID ( $tree,@GUI_CtrlID )), _GUICtrlTreeViewGetText ($tree, @GUI_CtrlID),"")
    MsgBox(0, "", $result)
EndFunc
Link to comment
Share on other sites

cool, I was thinking maybe onevent but i hadn't ever used it. o.o

always loops. ><

thanks a bunch! :)

No problem.

It took me a little bit to get used to onevent also. but ever since, i've found it to be much easier for most situations.

Good luck, and I like your program idea. pretty nifty ;)

Link to comment
Share on other sites

Yeah, lol I was thinking of making my own file format.

.foy

lol. xD

but knowing me it'd just be like a normal file but encrypted lol. xD

but then again it might allow me my own format of data storage. :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...