Thread: Treeview - TreeView_GetItem()

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    Treeview - TreeView_GetItem()

    Hi, i’m trying to handle the Tree-view’s NM_DBLCLK message, to display the name of the D Clicked item:

    Code:
    LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
     TVITEM tv;
     HWND hwndTree;
     char msg[MAX_PATH];
     int err;
    	
     switch(Msg)
     {
     ...
     case WM_NOTIFY:
      switch(((LPNMHDR) lParam)->code)
      {
       case NM_DBLCLK:
        hwndTree = GetDlgItem(hWndDlg, IDTREE);
        err =TreeView_GetItem(hwndTree,&tv);
        strcpy(msg, "You DCliked on ");
        strcat(msg, tv.pszText);
        MessageBox(NULL,msg, "MSG",MB_OK);
      }
     break;
     ...
    }
    But tv.pszText returns nothing and err gets zeroed. Please help to fix it.
    Thanx.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    Before you run TreeView_GetItem() you have to fill in the tv struct:
    Code:
    	TVHITTESTINFO hti;
    	POINT p1;
    	char achBuf[100];
    
    	GetCursorPos(&p1);
    	hti.flags=TVHT_ONITEM;
    	memcpy(&hti.pt, &p1, sizeof(POINT));
    	ScreenToClient(hwndTree, &hti.pt);
    
    	ZeroMemory(&tv, sizeof(TVITEM));
    	tv.hItem=(HTREEITEM)TreeView_HitTest(hwndTree, &hti);
    	tv.cchTextMax=100;
    	tv.pszText=achBuf;
    	tv.mask=TVIF_TEXT|TVIF_HANDLE;
    	TreeView_GetItem(hwndTree,&tv)
    Last edited by knutso; 05-26-2005 at 01:30 PM.

  3. #3
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    Thanx
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drag & Drop using TreeView
    By Devils Child in forum C# Programming
    Replies: 1
    Last Post: 03-24-2009, 07:02 AM
  2. How can I list processes in a treeview?
    By hileci555 in forum Windows Programming
    Replies: 0
    Last Post: 07-21-2008, 04:22 AM
  3. TreeView and Database
    By x64 in forum C# Programming
    Replies: 2
    Last Post: 01-14-2007, 07:42 PM
  4. Treeview Custom Draw
    By mobazr in forum Windows Programming
    Replies: 1
    Last Post: 06-21-2005, 02:51 AM
  5. Problem showing item in TreeView
    By Garfield in forum Windows Programming
    Replies: 4
    Last Post: 03-18-2004, 01:58 AM