News:

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

Mouse Over TreeView Node

Started by Robert Collins, November 21, 2005, 10:20:22 PM

Previous topic - Next topic

Robert Collins

Is there a way to capture the node (number or text associated with that node)  of a treeview on which the mouse is hovering over? I need to include a routine that will display the link which was added to the node tag property when I initialized the tree view.

When the user hovers or rests the mouse on top of a node I would like to get the node number, text data, or whatever info I can get and then extract the information from the tag property of that node so I can display it in the status bar of the application. This would be very similar to placing the mouse over a link on a Web page but I need it to work in an application.     

Tedd

I don't think tree-view supports that. But that's not to stop you from doing it anyway :wink

First you'll need to repeatedly check the mouse-cursor position to decide when it's 'hovering' (or is there another way to do this?)
Then you can do the following to find which (if any) item the cursor is over..

.data?
textBuff    db 256 dup (?)

.code
  .
  .

TreeGetItemOver proc hTreeView:HANDLE,pTvItem:DWORD
;hTreeView  is the handle of the tree-view we're using
;pTvItem    is a pointer to a TV_ITEM struct to receive the details of the item 'selected'
    LOCAL hti:TV_HITTESTINFO
    push esi
    lea esi,[hti]
    assume esi:ptr TV_HITTESTINFO
    invoke GetCursorPos, ADDR [esi].pt
    invoke ScreenToClient, hTreeView,ADDR [esi].pt
    invoke SendMessage, hTreeView,TVM_HITTEST,NULL,esi
    mov eax,[esi].hItem
    or eax,eax
    jz @fail
    mov esi,pTvItem
    assume esi:ptr TV_ITEM
    mov [esi].hItem,eax                         ;specify which item to get (the one the cursor is over)
    mov [esi].imask,TVIF_TEXT or TVIF_CHILDREN or TVIF_STATE or TVIF_PARAM      ;get info we're interested in (everything!)
    mov [esi].pszText,OFFSET textBuff           ;need somewhere to store the text
    mov [esi].cchTextMax,SIZEOF textBuff
    invoke SendMessage, hTreeView,TVM_GETITEM,0,esi
    xor eax,eax
    jmp @out
  @fail:
    mov eax,-1          ;over treeview control, but not on any actual item
  @out:
    pop esi
    assume esi:nothing
    ret
TreeGetItemOver endp

No snowflake in an avalanche feels responsible.