Jump to content
Sign in to follow this  
webmedic

how to creat dynamic tree menu items.

Recommended Posts

webmedic

Ok here goes. I'm looking over a few other scripts and trying to create what I need for an applauncher. Thanks to slimshady for the applauncher code. Now I'm merging this code with the tree menu code.

For this to work proeply though I need to read settings from an ini file so that the applications could be changed dynamicly whithout having to redoo the script. I'm trying to create dynamic tree menu items but even if I declair the items with a dim I still get errors.

Is there another way to do this?

$_var = IniReadSectionNames($Inifile)

   GUIDelete()
   GUICreate("GUI with more treeviews",340,200,-1,-1,BitOr($WS_MINIMIZEBOX,$WS_MAXIMIZEBOX,$WS_GROUP,$WS_CAPTION,$WS_POPUP,$WS_SYSMENU))
   $maintree = GUICtrlCreateTreeView (10,10,120,150)
   $aboutitem = GUICtrlCreateTreeViewItem ("About",$maintree)
   $spywareitem = GUICtrlCreateTreeViewItem ("Spyware",$maintree)
   $toolsitem = GUICtrlCreateTreeViewItem ("System Tools",$maintree)
   For $i = 1 To $_var[0]
     $_var2 = IniRead($Inifile, $_var[$i], "Parent", "error")
     $_var3 = IniRead($Inifile, $_var[$i], "Launch", "error")
     $_var4 = IniRead($Inifile, $_var[$i], "Des", "error")
     $_var5 = IniRead($Inifile, $_var[$i], "Icon", "error")

     $item[$i] = GUICtrlCreateTreeViewItem ($_var[$i], $_var2)


   Next

now eventually I would like ot be able to creat the parent nodes dynamicly also so that I would not have to have this

$aboutitem = GUICtrlCreateTreeViewItem ("About",$maintree)
   $spywareitem = GUICtrlCreateTreeViewItem ("Spyware",$maintree)
   $toolsitem = GUICtrlCreateTreeViewItem ("System Tools",$maintree)

hardcoded into it. Has anybody done anything even remotely like this before.

Share this post


Link to post
Share on other sites
Lazycat

Error is probably because you just did not define array.

$_var = IniReadSectionNames($Inifile)
   Dim $item[$_var[0]+1]

But way you try read Parent ID's from ini is unsafe... This way you need previously write right parent ID's to ini, so you can't create ini by hand. But I don't know which way you plan work with it.

Edit: If it helps, you can try to adapt this code, that load tree from file:

#include <GUIConstants.au3>
Dim $curlevel = 1
Dim $aTree = StringSplit(FileRead("Tree.dat", FileGetSize("Tree.dat")), @LF)

GUICreate("title")
$hTree = GUICtrlCreateTreeView(5, 5, 300, 200)

Dim $ahDepth[100]
$ahDepth[0] = $hTree

For $i = 1 to $aTree[0]
    $line = StringStripCR($aTree[$i])
    $markpos = StringInStr($line, "#")
    If $markpos <> $curlevel Then $curlevel = $markpos
    $ahDepth[$markpos] = GUICtrlCreateTreeViewItem(StringMid($line, $markpos+1), $ahDepth[$markpos-1])
Next

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    If $nMsg = -3 Then Exit
Wend

where Tree.dat is (example):

Tree.zip

But note, that it load structured tree.

Edited by Lazycat

Share this post


Link to post
Share on other sites
webmedic

thanks I also think I have a way to dynamicly create the parent trees. I did try adding the dims in there but that just gave more errors about the dim not being correct. My syntax was different than your however.

The only drawback to the way that I'm thinnking of doing this is that my tree will only be able to go one node deep but for this it is fine since I will only be having one node anyway.

Share this post


Link to post
Share on other sites
ReFran

Hello,

I pasted the code from Tree.zip into another Tab-Gui script. That works fine, but I'm not able to write the code I need to catch the result if a item in the tree-part is clicked.

Could someone extend tree.zip (tree.au3), so when a item is clicked a MsgBox view the result?

Best regards, Reinhard

Edited by ReFran

Share this post


Link to post
Share on other sites
ReFran

Ok, puzzled it out.

Only two lines under "$nMsg = GUIGetMsg()":

if $nMsg > $ahDepth[$markpos] - Ubound($aTree) + 1 then

msgBox(0,"",$aTree[$nMsg-($ahDepth[$markpos] - Ubound($aTree)+1)])

Best regards, Reinhard

Share this post


Link to post
Share on other sites
ReFran

.... and now the final version:

if $nMsg > $ahDepth[$markpos] - Ubound($aTree) + 1 and $nMsg < $ahDepth[$markpos] then

msgBox(0,"",$aTree[$nMsg-($ahDepth[$markpos] - Ubound($aTree)+1)])

which should be used, if you have more then only the tree on your GUI.

A question beside. Because my tree is a little bit longer I want to place a Collapse/Expand switch button on my tree tab GUI. Can that be done (Collapse/Expand)?

Best regards, Reinhard

Edited by ReFran

Share this post


Link to post
Share on other sites
Danny35d

Hi Webmedic I think this is what you want from a ini file...

#include <Array.au3>
#include <GUIConstants.au3>

$Inifile = @ScriptDir & '\TreeView.ini'

$_parent = IniReadSection($Inifile, "ParentNodes")
$_var = IniReadSectionNames($Inifile)

_ArrayDelete($_var, _ArraySearch($_var, "ParentNodes"))
$_var[0] = UBound($_var) - 1

GUIDelete()
GUICreate("GUI with more treeviews", 340, 200, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_GROUP, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU))
$maintree = GUICtrlCreateTreeView (10,10,120,150)
For $i = 1 To $_parent[0][0]
    $item = GUICtrlCreateTreeViewItem ($_parent[$i][0], $maintree)
    IniWrite($Inifile, "ParentNodes", $_parent[$i][0], $item)
Next

For $i = 1 To $_var[0]
    $_var2 = IniRead($Inifile, $_var[$i], "Parent", "error")
    If $_var2 <> "error" Then
        $_var2 = IniRead($Inifile, "ParentNodes", $_var2, "")
        $item = GUICtrlCreateTreeViewItem($_var[$i], $_var2)
        Iniwrite($Inifile, "TreeViewControl", $item, $_var[$i])
    EndIf
Next
GUISetState (@SW_SHOW)    ; will display an empty dialog box

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    $msg2 = IniRead($Inifile, "TreeViewControl", $msg, "")
    
    If $msg = $GUI_EVENT_CLOSE Then     
        ExitLoop
    EndIf
    
    If $msg2 <> "" Then
        $launch = IniRead($Inifile, $msg2, "Launch", "error")
        $des = IniRead($Inifile, $msg2, "Des", "error")
        $icon = IniRead($Inifile, $msg2, "Icon", "error")
        If $launch <> "error" Then RunWait($launch)
    EndIf   
Wend

For $i = 1 To $_parent[0][0]
    IniWrite($Inifile, "ParentNodes", $_parent[$i][0], "")
Next
IniDelete($Inifile, "TreeViewControl")
Exit

And this is what the TreeView.ini file look like...

[ParentNodes]

About =

Spyware =

System Tools =

[Regedit]

Parent = System Tools

Launch = C:\Windows\Regedit.exe

Des = Don't know what you want

Icon = 0

[Disk Cleanup]

Parent = System Tools

Launch = C:\Windows\System32\Cleanmgr.exe

[Adware]

Parent = Spyware

Launch = C:\Program Files\Lavasoft\Ad-Aware SE Personal\Ad-Aware.exe

Des = Don't know what you want

Icon = 0

[Microsoft AntiSpyware]

Parent = Spyware

Launch = C:\Program Files\Microsoft AntiSpyware\GIANTAntiSpywareMain.exe

Des = Don't know what you want

Icon = 0

Hope this will help you...

For this to work proeply though I need to read settings from an ini file so that the applications could be changed dynamicly whithout having to redoo the script. I'm trying to create dynamic tree menu items but even if I declair the items with a dim I still get errors.

Note: I didn't have any errors. I used AutoIt Beta .80 on Windows Xp Sp2...

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

Share this post


Link to post
Share on other sites
ReFran

"Hi Webmedic I think this is what you want from a ini file... "

Mmmh ...

the code is real nice done and works very well.

It surely would have been answered the question from WebMedic from March 15, 2005.

It would have been solved my problem I have had 3 days back.

But it don't really give an answer to the actual question if a Treeview can be collapsed/expanded by code.

However, thanks for sharing the code.

Reinhard

Share this post


Link to post
Share on other sites
Danny35d

It surely would have been answered the question from WebMedic from March 15, 2005.

It would have been solved my problem I have had 3 days back.

But it don't really give an answer to the actual question if a Treeview can be collapsed/expanded by code.

Sorry but I still a newbie after I posted the code I did notice the date was March 15, 2005 oh well it was a good learning....

anyway take a look to the new code I modify now it will Expand and Collpase the treeview....

Used the the ini file from the preview post.....


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

Share this post


Link to post
Share on other sites
ReFran

anyway take a look to the new code I modify now it will Expand and Collpase the treeview....

Cool, exactly what I needed.

It seems, from time to time it make sense to read the latest Beta-Helpfile.

However, copy 'n past is also fine.

Thanks for your help, Reinhard

Edited by ReFran

Share this post


Link to post
Share on other sites
BRD

Hi Danny35d. I have been interested in learning how to make a treeview and have read through these post and used your script with the above ini to see how it worked. At first I didn't have the "GuiTreeView.au3" but was able to find it on the internet. However, when I run the script, I get the errors listed below. Do you have any advice on how to resolve these problems?

C:\Program Files\AutoIt3\Include\GuiTreeView.au3(577,47) : ERROR: DllStructCreate(): undefined function.

$TEXT_struct = DllStructCreate ("char[260]")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Include\GuiTreeView.au3(583,36) : ERROR: DllStructDelete(): undefined function.

DllStructDelete ($TEXT_struct)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Include\GuiTreeView.au3(587,51) : ERROR: DllStructSetData(): undefined function.

DllStructSetData ($TVITEM_struct, 1, $TVIF_TEXT)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Include\GuiTreeView.au3(589,70) : ERROR: DllStructGetPtr(): undefined function.

DllStructSetData ($TVITEM_struct, 5, DllStructGetPtr ($TEXT_struct)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Program Files\AutoIt3\Include\GuiTreeView.au3(594,50) : ERROR: DllStructGetData(): undefined function.

$szText = DllStructGetData ($TEXT_struct, 1)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\jmcnew\My Documents\AutoIT\TreeviewTestt.au3(12,54) : ERROR: _ArraySearch(): undefined function.

_ArrayDelete($_var, _ArraySearch($_var, "ParentNodes")

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Documents and Settings\jmcnew\My Documents\AutoIT\TreeviewTestt.au3 - 6 error(s), 0 warning(s)

Share this post


Link to post
Share on other sites
ReFran

" .... it make sense to read the latest Beta-Helpfile."

To execute the file you have to install the latest Beta version otherwise you get above error messages.

Reinhard

Share this post


Link to post
Share on other sites
webmedic

wow back from the dead wish I would have gotten all this info when i asked a ling time ago.

Share this post


Link to post
Share on other sites
Danny35d

Sorry webmedic I found out about AutoIt on July 2005 or 4 months after you did the post ;)


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

Share this post


Link to post
Share on other sites
BRD

Thanks for the help, downloading the lastest beta fixed the problem.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.