i have a question trouble me,please help !!
I want to get treeview control item's text,so I send a messgae:TVM_GETITEM,and get the TV_ITEM structure's member:pszText.I thought this point is I need.but later I found it's wrong,I can't get the text I need.can you help me?.if you have an example ,it's best
Posted on 2004-01-31 23:55:27 by stupid bird
You have to set the mask and size of the buffer as well. This will get the text from the root item of a treeview. To get another item you must first find it's handle and use that where indicated:
LOCAL szString[256] :B

mov [tvi.pszText], OFFSET szString
mov D[tvi.cchTextMax], 255
mov D[tvi.imask], TVIF_TEXT

invoke SendMessage, [hTreeView], TVM_GETNEXTITEM, TVGN_ROOT, 0
mov D[tvi.hItem], eax ; Replace this with the handle of another item if necessary
invoke SendMessage, [hTreeView], TVM_GETITEM, 0, OFFSET tvi
Posted on 2004-02-01 01:13:56 by donkey
thank you
but I can't get the text just the same
there is my code:
.elseif eax == WM_NOTIFY
mov edi,lParam
assume edi:ptr NM_TREEVIEW
.if .hdr.code == TVN_SELCHANGED
invoke RtlZeroMemory,offset szName,sizeof szName
mov eax,offset szName
mov @stTreeItem.pszText,eax
push .itemNew.hItem
pop @stTreeItem.hItem
mov @stTreeItem.cchTextMax,63
mov @stTreeItem.imask, TVIF_TEXT
invoke SendMessage,hTree,TVM_GETITEM,0,addr @stTreeItem
invoke _Error,offset szName


the _Error function can display the string in szName,but when I run the program,it's show that it's nothing in szName,i dont know why?
Posted on 2004-02-01 10:31:56 by stupid bird
You should not assume that Windows will actually use the szName buffer. It is a very stupid "random feature" of the treeview that Windows may ignore the buffer you pass and create a new one. Try :

invoke _Error,@stTreeItem.pszText

And see if it helps.

The returned text will not necessarily be stored in the original buffer passed by the application. It is possible that pszText will point to text in a new buffer rather than place it in the old buffer.

I tried with this and it works perfectly (GoAsm syntax) Note that I did not bother to move the information from one TVITEM structure to another, I just used the same one passed in the notification message:


mov edi,[lParam]
jne >.NEXTNM
mov D[edi+NM_TREEVIEW.itemNew.imask],TVIF_TEXT
mov D[edi+NM_TREEVIEW.itemNew.pszText],OFFSET TextBuffer
mov D[edi+NM_TREEVIEW.itemNew.cchTextMax],MAX_PATH
add edi,NM_TREEVIEW.itemNew
invoke SendMessage,[hTreeView],TVM_GETITEM,0,edi
PrintString(TextBuffer) ; Vkim's PrintString debug macro
xor eax,eax
inc eax
Posted on 2004-02-01 11:37:51 by donkey