I can't put text on TreeView.How can i do it?




WM_CREATE:
CreateWindowEx ...............
mov tvinsert.hParent,NULL
mov tvinsert.hInsertAfter,TVI_ROOT
mov tvinsert.item.imask,TVIF_TEXT
mov tvinsert.item.pszText,offset Parent
mov tvinsert.item.iImage,0
mov tvinsert.item.iSelectedImage,0

invoke SendMessage,hwndTree,TVM_INSERTITEM,0,addr tvinsert xor eax,eax
ret

Posted on 2003-03-19 07:11:23 by sysnet
Try to redraw the window after you insert the text. If this doesn't work check to make sure that you have a valid handle to the treeview (i.e. it is not INVALID_HANDLE_VALUE or NULL). Also be sure to get the Handle of your root item before returning, you have not done that in your example. You will need this handle for subsequent calls.

invoke RedrawWindow, hwndTree, NULL, NULL, RDW_NOCHILDREN or RDW_UPDATENOW or RDW_INVALIDATE
Posted on 2003-03-19 10:28:23 by donkey
Oh,I do like this ,but it also have wrong



push 0
push hInstance
push 0
push hwnd
push 300
push 250
push 10
push 20
push WS_CHILD OR WS_VISIBLE OR TVS_HASLINES OR TVS_LINESATROOT OR TVS_HASBUTTONS
push offset TreeViewClass
push offset _class
push WS_EX_CLIENTEDGE
call CreateWindowEx
mov hwndTree,eax

mov tvinsert.hParent,NULL
mov tvinsert.hInsertAfter,TVI_ROOT
mov tvinsert.item.imask,TVIF_TEXT
mov tvinsert.item.pszText,offset Parent
mov tvinsert.item.iImage,0
mov tvinsert.item.iSelectedImage,0

push offset tvinsert
push 0
push TVM_INSERTITEM
push hwndTree
call SendMessage
mov hParent,eax

push RDW_NOCHILDREN or RDW_UPDATENOW or RDW_INVALIDATE
push 0
push 0
push hwndTree
call RedrawWindow

xor eax,eax
ret

Posted on 2003-03-20 02:43:57 by sysnet
Did you call the api InitCommonControls and included comctl32.lib?
Posted on 2003-03-20 02:47:08 by roticv
Hi sysnet

Try to zero the tvinsert structure before you use it or allocate it in your .DATA section with a <0> value. If it is not initialized perhaps you are getting weird numbers in the statemask and that is effecting the display of text. Outside of that I can find nothing that is missing from your first post, I have checked some of my apps that have a treeview and it is essentially the same although I use images. If the treeview is visible then the handle is valid (in the CreateWindowEx version at least) and the common control style is loaded so InitCommonControlsEx is not a problem though it should be executed anyway.
Posted on 2003-03-20 07:09:17 by donkey
You don't have to redraw the treeview at all, you are missing a very important value.. the cchTextMax value..

The cchTextMax tells the treeview how large the text buffer of the item you are inserting is.. without it, the treeview it is 0 so the treeview thinks there is no text in the pszText buffer...

if your pszText is 10 bytes try this:


mov tvinsert.hParent,NULL
mov tvinsert.hInsertAfter,TVI_ROOT
mov tvinsert.item.imask,TVIF_TEXT
mov tvinsert.item.cchTextMax, 10 ; <--- text length.....
mov tvinsert.item.pszText,offset Parent
mov tvinsert.item.iImage,0
mov tvinsert.item.iSelectedImage,0

push offset tvinsert
push 0
push TVM_INSERTITEM
push hwndTree
call SendMessage
mov hParent,eax
Posted on 2003-03-20 16:39:41 by Gunner
Can't believe I missed that. And I was comparing it directly to my working code.

Mmm. I was just thinking about why you would need to specify the cchTextMax attribute so I checked over my old code again and checked the docs. MSDN says it only need to be specified if you are recieving information:
Size of the buffer pointed to by the pszText member, in characters. If this structure is being used to set item attributes, this member is ignored.

I have checked some code that I have written and have no problems if I don't specify cchTextMax when writing to the treeview, as a matter of fact I couldn't find a single instance where I set it

Donkey
Posted on 2003-03-20 16:50:25 by donkey
This is a proc from a working program that I use, it creates the root item for a "catalog" of items maybe it'll help a bit. Maybe try to substitute the proc for your code just to check it out
AddCatalog proc hTree:DWORD,TVILABEL:DWORD

LOCAL tvinsert :TVINSERTSTRUCT

mov tvinsert.hParent,NULL
mov tvinsert.hInsertAfter,TVI_ROOT
mov tvinsert.item._mask, TVIF_TEXT + TVIF_IMAGE + TVIF_SELECTEDIMAGE + TVIF_STATE
mov eax,TVILABEL
mov tvinsert.item.pszText,eax

mov tvinsert.item.stateMask,TVIS_BOLD
mov tvinsert.item.state,TVIS_BOLD

; Only if you use images in your treeview
mov eax,IML_CATALOG
mov tvinsert.item.iImage,eax
mov tvinsert.item.iSelectedImage,eax

invoke SendMessage,hTree, TVM_INSERTITEM,0,addr tvinsert
push eax
invoke RedrawWindow, hTree, NULL,NULL, \
RDW_NOCHILDREN or RDW_UPDATENOW or RDW_INVALIDATE
pop eax
ret
AddCatalog endp
Donkey
Posted on 2003-03-20 18:54:30 by donkey
Eh, that's right.. have so many thing floating in this head of mine...

How about this... sysnet, where is tvinsert declared? Is it local to the proc? if so you can't pass the offset, you have "load" it first:

Incorrect:
push offset tvinsert
push 0
push TVM_INSERTITEM
push hwndTree
call SendMessage

Correct:
lea eax, tvinsert
push eax
push 0
push TVM_INSERTITEM
push hwndTree
call SendMessage

or use invoke like donkey did and masm will do the above for you:

invoke SendMessage, hwndTree, TVM_INSERTITEM, 0, addr tvinsert
Posted on 2003-03-20 19:10:12 by Gunner