Condividi tramite


CTreeCtrl::GetItemImage

Each item in a tree view control can have a pair of bitmapped images associated with it.

BOOL GetItemImage(
   HTREEITEM hItem,
   int& nImage,
   int& nSelectedImage 
) const;

Parameters

  • hItem
    The handle of the item whose image is to be retrieved.

  • nImage
    An integer that receives the index of the item's image within the tree view control's image list.

  • nSelectedImage
    An integer that receives the index of the item's selected image within the tree view control's image list.

Return Value

Nonzero if successful; otherwise 0.

Remarks

The images appear on the left side of an item's label. One image is displayed when the item is selected, and the other is displayed when the item is not selected. For example, an item might display an open folder when it is selected and a closed folder when it is not selected.

Call this function to retrieve the index of the item's image and its selected image within the tree view control's image list.

Example

HTREEITEM hmyItem = m_TreeCtrl.GetSelectedItem();

// If the selected image is the same as the nonselected image
// then make the selected image one more than the nonselected image.
if (m_TreeCtrl.ItemHasChildren(hmyItem))
{
   HTREEITEM hItem = m_TreeCtrl.GetChildItem(hmyItem);
   int nImage, nSelectedImage;

   while (hItem != NULL)
   {
      m_TreeCtrl.GetItemImage(hItem, nImage, nSelectedImage);

      if (nImage == nSelectedImage)
      {
         m_TreeCtrl.SetItemImage(hItem, nImage, nImage + 1);
      }

      hItem = m_TreeCtrl.GetNextSiblingItem(hItem);
   }
}

Requirements

Header: afxcmn.h

See Also

Reference

CTreeCtrl Class

Hierarchy Chart

CTreeCtrl::SetItemImage

CImageList Class

Other Resources

CTreeCtrl Members