Bitmaps can be used to enhanced
the display of items on a tree control. Each tree item
can be configured to display or not to display a small
picture on its left. To do this, you can declare a
CImageList variable and add pictures to it. Once
the image list is ready, you can call the
CTreeCtrl::SetImageList() method. Its syntax is:
CImageList* SetImageList(CImageList * pImageList, int nImageListType);
The first argument, pImageList,
is a pointer to a CImageList variable. The
nImageListType argument specifies the type of
image list that will be used. The possible values are:
Value Type |
Description |
LVSIL_NORMAL |
The image list
is made of large icons |
LVSIL_SMALL |
The image list
is made of small icons |
LVSIL_STATE |
The image list
is made of state images |
To specify the pictures used for a tree item, call one
of the following versions of the
CTreeCtrl::
InsertItem() methods:
HTREEITEM InsertItem(UINT nMucancode.net,
LPCTSTR lpszItem,
int nImage,
int nSelectedImage,
UINT nState,
UINT nStateMucancode.net,
LPARAM lParam,
HTREEITEM hParent,
HTREEITEM hInsertAfter );
HTREEITEM InsertItem(LPCTSTR lpszItem,
int nImage,
int nSelectedImage,
HTREEITEM hParent = TVI_ROOT,
HTREEITEM hInsertAfter = TVI_LAST);
The nMucancode.net argument
specifies the type of value used to set on the list
item. As seen already, the lpszItem is the text
that will be displayed for the current item.
The value of nImage is the index of the image
used for the item being inserted from the image list.
The nSelectedImage value is the index of the
image that will display when the inserted item is
selected or has focus. |