Thread: Getting the lParam associated to a treeview's item?

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291

    Getting the lParam associated to a treeview's item?

    Hello, I'm trying to get the 32-bit value associated with an item of a treeview control, but I'm not able to find the way of do it; I'm able to get the pszText associated to an item, so the item pointer (HTREEITEM) is right. I have been reading on the Win32 Prog Reference and find the next explanation referred to the struct TV_ITEM used in the TVM_GETITEM message:

    Code:
    Pointer to a TV_ITEM structure that specifies the information to retrieve and receives information about
    the item. When the message is sent, the hItem member identifies the item to retrieve information about
    and the mask member specifies the attributes to retrieve.
    
    If mask specifies the TVIF_TEXT value, the pszText member must contain the pointer to the buffer that
    receives the item text and the cchTextMax member must specify the size of the buffer.
    If mask specifies the TVIF_STATE value, the stateMask member indicates which item states are to be returned.
    So can I only get the text and the state?
    That's what I do to get the item:
    Code:
    char gbff[300];
    DWORD dwValue;
    HTREEITEM htree;
    
    htree=(HTREEITEM)SendMessage(theTreeViewControlHandle,TVM_GETNEXTITEM,(WPARAM)TVGN_ROOT,(LPARAM)htree);
    memset(&tvi,0,sizeof(tvi));
    tvi.mask=TVIF_PARAM|TVIF_TEXT;
    tvi.pszText=gbff;
    tvi.cchTextMax=300;
    tvi.lParam=dwValue;
    tvi.hItem=htree;
    SendMessage(GetDlgItem(hwnd,ARBRE),TVM_GETITEM,0,(LPARAM)&tvi);
    
    MessageBox(hwnd,gbff,"",MB_OK);
    sprintf(gbff,"%d, %d",LOWORD(dwValue),HIWORD(dwValue));
    MessageBox(hwnd,gbff,"",MB_OK);
    From that code I get the item text in the first alert, but "0, 0" on the second alert. I'm afraid that as the W32 Prog Ref says, the only 'getable' values are the text and the state. I'm doing it right, or there's a different way than TVM_GETITEM to get the lParam associated to an item?

    Thank's in advance.
    Niara
    Last edited by Niara; 11-04-2006 at 02:28 PM.

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    4
    Try the following.
    Code:
    char gbff[300];
    DWORD dwValue;
    HTREEITEM htree;
    
    htree=(HTREEITEM)SendMessage(theTreeViewControlHandle,TVM_GETNEXTITEM,(WPARAM)TVGN_ROOT,(LPARAM)htree);
    memset(&tvi,0,sizeof(tvi));
    tvi.mask=TVIF_PARAM|TVIF_TEXT;
    tvi.pszText=gbff;
    tvi.cchTextMax=300;
    //tvi.lParam=dwValue;No need to set this value. It will be set in the output.
    tvi.hItem=htree;
    SendMessage(GetDlgItem(hwnd,ARBRE),TVM_GETITEM,0,(LPARAM)&tvi);
    
    MessageBox(hwnd,gbff,"",MB_OK);
    sprintf(gbff,"%d, %d",LOWORD(tvi.lParam),HIWORD(tvi.lParam)); // Pass tvi.lmParam instead of dwValue.
    MessageBox(hwnd,gbff,"",MB_OK);

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Hello SoLoMoN BaNdA, thanks for your time.

    I tryed but I get the same result. That's how I add the new item
    Code:
    TV_ITEM tvi;
    TVINSERTSTRUCT tvis;
    memset(&tvi,0,sizeof(tvi));
    tvi.mask=TVIF_TEXT|TVIF_IMAGE|TVIF_SELECTEDIMAGE|TVIF_STATE;
    tvi.state=TVIS_BOLD;
    tvi.pszText=TEXT(root);
    tvi.cchTextMax=lstrlen(tvi.pszText);
    tvi.iImage=1;
    tvi.iSelectedImage=1;
    tvi.lParam=MAKELPARAM(14,852);
    
    memset(&tvis,0,sizeof(tvis));
    tvis.hParent=TVI_ROOT;
    tvis.hInsertAfter=TVI_LAST;
    tvis.item=tvi;
    SendMessage(arbre,TVM_INSERTITEM,0,(LPARAM)&tvis);
    I think that there's no error, if not the item won't be added. Maybe I'm doing something wrond here but I can't see what.

    Niara

  4. #4
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Uf, what a silly problem: I was missing the TVIF_STATE on the tv_item mask. Problem solved, now it works.

    Thanks for read it.
    Niara

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    4
    Quote Originally Posted by Niara
    Hello SoLoMoN BaNdA, thanks for your time.

    I tryed but I get the same result. That's how I add the new item

    I think that there's no error, if not the item won't be added. Maybe I'm doing something wrond here but I can't see what.

    Niara
    Yes. that is how you should add the item, because for that you have to send all the information about that item.
    But in this case, since you want info rather than send info, you do not have to set lParam to the value of dwValue. Even if you did, the changes in lParam will not be show in dwValue.

    Quote Originally Posted by Niara
    I was missing the TVIF_STATE on the tv_item mask. Problem solved, now it works.Niara
    Yes, I missed it too. But even then, I believe that you should make the changes I mentioned. Please tell me if I am wrong. I didn't compile and see.

  6. #6
    Registered User
    Join Date
    Mar 2005
    Location
    Juneda
    Posts
    291
    Hey SoLoMoN BaNdA, you're right.

    After testing your first post's code I didn't modifyed the
    Code:
    sprintf(gbff,"%d, %d",LOWORD(tvi.lParam),HIWORD(tvi.lParam))
    part on my code, but I still thought that assigning a dword variable to the 'tv_item.lParam' would work, such as it works with listviews. but after read your last post I tryed and does not work, like the 'lParam' value is only to assign value, not to retrieve.

    Thank's to clarify that last point.
    Niara

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Immediate programming help! Please!
    By xMEGANx in forum C++ Programming
    Replies: 6
    Last Post: 02-20-2008, 12:52 PM
  2. Retail Outlet Managment System - the 4th
    By Presidentofusa in forum C Programming
    Replies: 3
    Last Post: 11-10-2007, 10:44 PM
  3. destroywindow() problem
    By algi in forum Windows Programming
    Replies: 6
    Last Post: 03-27-2005, 11:40 PM
  4. Constructive Feed Back (Java Program)
    By xddxogm3 in forum Tech Board
    Replies: 12
    Last Post: 10-10-2004, 03:41 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM