this is not a windows question
i have been trying to display some information similar to a treeview control where there are parents items and child items and where i can navigate the "treeview" using the up/down arrow keys and expand and collapse the parent items using the right/left arrow keys.
i have code some parts like expanding and collapsing when i press right/left arrow keys but i dont know how to do it on children items.
my english is not good but i hope i have explained my self very well

this is basically the function that draws the items as a treeview.
edi is the color, so when an item is selected its color changes to red.
printtext prints the itemname at x, y location using the edi color.


DrawMenu proc uses ebx esi edi x:DWORD, y:DWORD
local parent:DWORD

invoke UpdateValues

xor ebx, ebx
mov esi, offset Parents

.repeat
mov edi, 0FF00FFFFh
.if ebx == selItem
mov edi, 0FFFF0000h
.endif

invoke PrintText, esi, x, y, edi
.if .PARENT.value != 0 ; if expanded draw children

mov parent, ebx
push ebx
push esi

xor ebx, ebx
mov esi, offset Children
add x, 10

.repeat

mov eax, parent
.if .ITEM.parent == eax
add y, 10
invoke PrintText, esi, x, y, 0FFFFFFFFh
.endif

add esi, SIZEOF ITEM
inc ebx

.until ebx == ChildrenCount

sub x, 10
pop esi
pop ebx


.endif

add esi, SIZEOF PARENT
add y, 10
inc ebx
.until ebx >= ParentCount


ret
DrawMenu endp

when my program start im reading the parents and child from an ini file.
the structure is like this for parents
value=0 collapsed value=1 expanded

name=PARENT 0
value=0

and child: parent=0 child parent is parent 0, if 1 then parent is parent 1


name=CHILD 0
value=0
parent=0

the UpdateValue function updates the selected Item: selItem
UpdateValues proc uses esi
invoke isKeyPressed(KEY_UP)
.if eax
.if selItem > 0
dec selItem
.else
m2m selItem, ParentCount
dec selItem
.endif
.endif

invoke isKeyPressed(KEY_DOWN)
.if eax
mov eax, ParentCount
dec eax

.if selItem < eax
inc selItem
.else
mov selItem, 0
.endif
.endif

invoke isKeyPressed(KEY_RIGHT)
.if eax

mov eax, selItem
imul eax, SIZEOF PARENT
add eax, offset Parents
.if .PARENT.value < 1
inc .PARENT.value
.endif

.endif

invoke isKeyPressed(KEY_LEFT)
.if eax

mov eax, selItem
imul eax, SIZEOF PARENT
add eax, offset Parents

.if .PARENT.value > 0
dec .PARENT.value
.endif

.endif

ret
UpdateValues endp

with this code i can expand/collapse parents using the right/down arrow key and highlight the selected parent and also navigate parents using the down/up arrow key, but when a parent is expanded i cant navigate the children or highlight them, etc
any idea on how to fix this? any better solutions?

thank you

Posted on 2008-07-01 18:17:57 by SADE
Use linked-lists. This is design specific. The best help you have is you because you know the design of the system.
Posted on 2008-07-03 14:21:42 by XCHG