WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Control Manager
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Retrieve a SysTreeView Controls Selected Text

 Keywords:  get grab SysTreeView32 Selected Item Text

QUESTION:

Hello, Is there any way to find the value of a node in a SysTreeView32 control? There are ways to set the node (cSetTVItem) that gets focus but what I want to do is copy the label text from the tree item and place it on the clipboard to use later...

Any thoughts

ANSWER:

Do you need to get the selected item text?

if so you can try this fuction , use the ctrl mngr extender to get the treeview handle.

;------------------------------------------------------------------------------;
;TreeGetSelectedItem : Retrieves the selected item text.                       ;
;Guido 12/02                                                                   ;
;------------------------------------------------------------------------------;
;htree : treeview handle                                                       ;
;------------------------------------------------------------------------------;
;Returns : Selected item. If the item is a child item returns a tab delimited  ;
;          list representing the item hierarchy.                               ;
;Note    : The max item text is set to 500 , change it for bigger item text.   ;
;------------------------------------------------------------------------------;
#definefunction TreeGetSelectedItem(htree)
user32=strcat(dirwindows(1),"user32.dll")
TVM_GETNEXTITEM=4352+10
TVM_GETITEM=4352+12
TVGN_CARET=9
TVGN_PARENT=3
TVIF_HANDLE=16
TVIF_TEXT=1

MAXTEXT=500 ;change this for bigger text
hitem=dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETNEXTITEM,long:TVGN_CARET,long:0) 
if hitem
  TVITEM=binaryalloc(40) 
  mask=TVIF_TEXT|TVIF_HANDLE
  binarypoke4(TVITEM,0,mask) ;mask
  binarypoke4(TVITEM,4,hitem);hItem

  bufsize=MAXTEXT+1
  textbuf=binaryalloc(bufsize)
  binarypoke4(TVITEM,16,intcontrol(42,textbuf,0,0,0)) ;pszText
  binarypoke4(TVITEM,20,MAXTEXT) ;cchTextMax

  dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETITEM,long:0,lpbinary:TVITEM) 
  binaryeodset(textbuf,bufsize)

  item=binarypeekstr(textbuf,0,bufsize) ;selected item
  
  ;search for parent items
  while hitem !=0
    hitem=dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETNEXTITEM,long:TVGN_PARENT,long:hitem) 
    if hitem
      binarypoke4(TVITEM,4,hitem) ;hItem
      dllcall(user32,long:"SendMessageA",long:htree,long:TVM_GETITEM,long:0,lpbinary:TVITEM) 
      item=iteminsert(binarypeekstr(textbuf,0,bufsize),0,item,@tab)
    endif
  endwhile

  binaryfree(TVITEM)
  binaryfree(textbuf)
  return item
else
  return ""
endif
#endfunction

Article ID:   W15397
File Created: 2003:05:13:11:27:28
Last Updated: 2003:05:13:11:27:28