News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Finding a certain treeview item.

Started by minor28, November 19, 2009, 02:22:04 PM

Previous topic - Next topic

minor28

I have a treeview with up to 8 levels under a root node and I want to select a certain treeview (saved in registry with appropriate data) from the newly populated control.

The node text are not unique. The param is occupied for other reasons. Scaning the nodes will only hit the first occurance so this is not a solution.

I have tryed TVM_GETITEMRECT and TVM_HITTEST but the saved rect value depends on scroll position, window status and how many of parent nodes that are expanded. I have not found this as a solution.

I have played with full path from root to selected item. It is easier to get the full path than doing the reverse order.

Any solution I haven't thought about would be appracieted.

sysfce2

How is the control populated?
If you are using TVM_INSERTITEM, are you saving the returned handle?

minor28

Thank you for your answer. I believe handles are not persistant. I have a solution with indexing the path from selected node to root.

The save process is like this:

SaveSelectedNode proc
LOCAL arrData[36]:byte
LOCAL i:dword

;Fill array with 0FFFFFFFFh
lea edi,arrData
mov ecx,sizeof arrData
mov eax,-1
rep stosb

;Current selected node
invoke SendMessage,hTRV,TVM_GETNEXTITEM,TVGN_CARET,0
push eax
invoke NodeIndex,hTRV,eax
mov dword ptr [arrData],eax

;Get parent
pop eax
mov i,1
.while eax!=0
invoke SendMessage,hTRV,TVM_GETNEXTITEM,TVGN_PARENT,eax
push eax
invoke NodeIndex,hTRV,eax
cmp eax,-1
je @F
mov ecx,eax
mov eax,sizeof dword
mul i
mov dword ptr [arrData+eax],ecx
pop eax
inc i
.endw
@@:

invoke "Write array to registry"

ret

SaveSelectedNode endp


To select the saved node I use this process:

SelectSavedNode proc
LOCAL arrData[36]:byte
LOCAL i:dword
LOCAL hNode:dword
LOCAL hParentNode:dword

;Retrieve saved data
invoke "Read arrray from registry"

;Number of levels
mov i,0
.while i<9
mov eax,sizeof dword
mul i
mov eax,dword ptr [arrData+eax]
cmp eax,-1
je @F
inc i
.endw
@@:
dec i ;Root index

invoke SendMessage,hTRV,TVM_GETNEXTITEM,TVGN_ROOT,0
mov hNode,eax
dec i
.while i!=-1
push hNode
pop hParentNode
invoke SendMessage,hTRV,TVM_GETNEXTITEM,TVGN_CHILD,hNode
mov hNode,eax
mov eax,sizeof dword
mul i
mov eax,dword ptr [arrData+eax]
xor ecx,ecx
.while ecx<eax
push ecx
push eax
invoke SendMessage,hTRV,TVM_GETNEXTITEM,TVGN_NEXT,hNode
mov hNode,eax
pop eax
pop ecx
inc ecx
.endw
dec i
.endw

invoke SendMessage,hTRV,TVM_EXPAND,TVE_EXPAND,hParentNode
invoke SendMessage,hTRV,TVM_SELECTITEM,TVGN_FIRSTVISIBLE,hParentNode
invoke SendMessage,hTRV,TVM_SELECTITEM,TVGN_CARET,hNode
invoke SetFocus,hTRV

SelectSavedNode endp


This expand selected node parent and make it first visible and highlight the selected node.

Improvements will be appreciated.

sysfce2

Ok, I always like to ask the obvious questions first.  I have certainly been tripped up by that many a time ;-)

What about creating your own (unique) handles and using them to index the current handle?  A few bits could be saved for encoding an index to which saved treeview you want.

I'll take a closer look at your code later, I've got to head off to work now.