CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Tree Control

  1. #1
    Join Date
    Jul 2007
    Posts
    20

    Tree Control

    Hi
    can any one tell how can i do ,when we click the different child node in tree control, i want to display different bitmap image on the dialog box when i click to each child node as my option
    regards
    vasanth

  2. #2
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: Tree Control

    Hello,

    If I understood your problem correctly, you have a tree control and a bitmap is associated with each of its child item. When the user selects a child item, corresponding bitmap should be displayed in the dialog box. Is it not so?

    You can use SetItemData and GetItemData member functions of CTreeCtrl or derived objects to store / retrieve the bitmap IDs.

    Here is a sample code for storing the bitmaps as data of each item:

    [CODE]HTREEITEM hItem;
    m_Tree.SetItemData(hItem = m_Tree.InsertItem("1"), IDB_BITMAP1);
    m_Tree.SetItemData(m_Tree.InsertItem("11", hItem), IDB_BITMAP2);
    m_Tree.SetItemData(m_Tree.InsertItem("12", hItem), IDB_BITMAP3);
    m_Tree.SetItemData(m_Tree.InsertItem("13", hItem), IDB_BITMAP4);
    m_Tree.SetItemData(hItem = m_Tree.InsertItem("2"), IDB_BITMAP5);
    m_Tree.SetItemData(m_Tree.InsertItem("21", hItem), IDB_BITMAP6);
    m_Tree.SetItemData(m_Tree.InsertItem("22", hItem), IDB_BITMAP7);
    /CODE]

    In the event of TVN_SELCHANGED for the tree control, you can write the code to display the appropriate bitmap in the panel.

    Code:
    HTREEITEM hItem = m_Tree.GetSelectedItem();
    if (hItem)
    {
    	CStatic* pPanel = (CStatic*) GetDlgItem(IDC_PANEL);
    	UINT ID = m_Tree.GetItemData(hItem);
    	CClientDC DC(pPanel);
    	CDC MemDC;
    	if (MemDC.CreateCompatibleDC(&DC))
    	{
    		CBitmap Bitmap;
    		Bitmap.LoadBitmap(ID);
    		BITMAP BM;
    		Bitmap.GetBitmap(&BM);
    		CBitmap* pBitmap = MemDC.SelectObject(&Bitmap);
    		DC.BitBlt(0, 0, BM.bmWidth, BM.bmHeight, &MemDC, 0, 0, SRCCOPY);
    		MemDC.SelectObject(pBitmap);
    		Bitmap.DeleteObject();
    		MemDC.DeleteDC();
    	}
    }
    You will be able to view the bitmap associated with each item of the selection.

    Regards,
    Pravin.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured