Hi all,

i was looking for some idea of how to save a TreeView to file... That's to restore it back opening my application again.

If any help, Thx, bit7
Posted on 2003-12-06 08:15:26 by Bit7
What you are looking for is a way to store hierarchical data. The particular solution for your application depends on alot of factors. How much data are you talking about, how many possible nested levels are there, do you need to search the data or just plug it into the treeview. If you are looking for a flexible means to do it and need to store alot of data the best route would be to store the information in a database then rebuild the treeview as needed. You can also create your own file structure and do it that way but searching with SQL is more flexible. You cannot avoid storing the data in some form and rebuilding the treeview each time your program starts because the treeview structure is handle based and those are assigned at runtime. For example you might use a custom structure:

MyTreestruct struct

ThisID dd ?
ParentID dd ?
Label db 256 DUP (?)
TreeView TVITEM <>
MyTreestruct ends


Then just write the array of structures to a binary file. This method can be randomly stored.

Others use an offset method. Each item has the offset from the last stored with it and you rebuild the treeview from that. This method must be sequetially stored.

root (0)

-------child (+1)
-------child2 (0)
------- ------- subchild (+1)
------- ------- subchild2 (0)
------- child3 (-1)
------- ------- subchild (+1)
------- ------- subchild2 (0)
------- ------- subchild3 (0)
------- ------- ------- subsubchild (+1)
------- ------- subchild4 (-1)
------- child4 (-1)
Posted on 2003-12-06 08:56:06 by donkey
Hi Donkey, can you write a small example ?

I was looking for that too.

The goal is build a treeview based on the contents of a directory and subdirs, with files inside.

For example, a directory like:



Dir01
| |
| |SubDir01
| |_ FIle01.txt
| |_ FIle02.txt
| |_ FIle03.txt
| |
| |SubDir02
| | |_ FIle01a.txt
| | |_ FIle02b.txt
| | |_ FIle03c.txt
| |
| |_ SubDir02a
| |_ FIle03d.txt
|
|
|_ FIle04.txt
|_ FIle05.txt



See ? he get the structures of the directorys, and replicates it on a treeview, then, he write a .txt (or .ini) file with the data that is used to he open it.

So. it does:

a) Create a treeview data based on a subdir, and output a text based file(called, for example. Default.txt).
b) Open the Default.txt, if the user wants to see teh structure of that dir.

I mean....if the user has 02 different types of data inside their own subdirs and files. And he want to store 02 types of "default.txt"...opening as he wish to see his treeview on each data.

For example one type of data is related to a treeview on a directory of bitmap images, and other is based on music or something.

He creates the directory "default.txt" for the bitmaps.....And then he creates another for the music.

If he wants to se the treeview for the music, he load the related "default.txt" ...if he wants to see the treeview for the bitmaps, he loads the other"default.txt"


Best Regards,

Guga
Posted on 2003-12-06 12:01:53 by Beyond2000!
Hi Guga,

The example would be pretty complicated to churn out in a few hours. I will see what I can come up with but no gaurantee that I will be finished soon. A good example of how it works is the way menus are stored in resources, they are hierarchical in nature as well and use the second sequential method as near as I can tell. I was thinking about doing something like this soon anyway so I might take a shot if I have some time.
Posted on 2003-12-06 12:15:33 by donkey
Hi Donkey

Ok, Tks :alright: I'll be waiting


Best Regards,

Guga
Posted on 2003-12-06 12:37:10 by Beyond2000!

Hi Donkey

Ok, Tks :alright: I'll be waiting


Best Regards,

Guga

:grin: If I get to it, I have alot on my plate right now :grin:
Posted on 2003-12-06 13:04:11 by donkey
ooops, forget to thanks :)
I'm implementing now the MyStructure strategy :)

B7
Posted on 2003-12-17 14:49:33 by Bit7
i've done te SaveToFile, it's based on a recursive call



proc WriteParentNode uses eax, hFile:dword, depth:dword, htv:dword, hItem:dword

; diria che ormai la xe piuttosto stabile


call WriteNode, [hFile], [htv], [hItem], 0

; se li ga, salvo tutti i fioi....

@@wChild: call SendMessageA, [htv], TVM_GETNEXTITEM, TVGN_CHILD, [hItem]
cmp eax,0
je @@wBrother

; questa devi esser ricorsiva !
call WriteParentNode, [hFile], 0, [htv], eax

; se li ga, salvo tutti i fradei....

@@wBrother: call SendMessageA, [htv], TVM_GETNEXTITEM, TVGN_NEXT, [hItem]

cmp eax, 0
je @@rtProc

call WriteNode, [hFile], [htv], eax, [hItem]
mov [hItem], eax

jmp @@wChild


@@rtProc: ret

endp WriteParentNode





Thx again donkey :)
Posted on 2003-12-20 10:27:51 by Bit7
Hmm


can someone post an working example ?


Best regards,

guga
Posted on 2004-01-24 21:46:54 by Beyond2000!
Of course I don't have the time to write a fulfledged example here... but here's my shot at it.. (in pseudo code whoohoo)



[start]
go to root - write root to file - using tv_item struct + index being 0 at root

a))
getchild
...if child = 0 then jmp b))

inc index
get tv_item struct

write this to file

jmp a))

b))
getnextsibling
... if getnext sibling = 0 then jmp c))

keep index
get tv_item struct

write this to file

jmp a))


c))

getparent
...if getparent == root then jmp d))

dec index

jmp b))


d))
end.
Posted on 2004-01-24 23:24:55 by JimmyClif