// Insert a root item using the structure. We must// initialize a TVINSERTSTRUCT structure and pass its// address to the call.
TVINSERTSTRUCT tvInsert;
tvInsert.hParent = NULL;
tvInsert.hInsertAfter = NULL;
tvInsert.item.mask = TVIF_TEXT;
tvInsert.item.pszText = _T("United States");
HTREEITEM hCountry = m_TreeCtrl.InsertItem(&tvInsert);
// Insert subitems of that root. Pennsylvania is// a state in the United States, so its item will be a child// of the United States item. We won't set any image or states,// so we supply only the TVIF_TEXT mask flag. This// override provides nearly complete control over the// insertion operation without the tedium of initializing// a structure. If you're going to add lots of items// to a tree, you might prefer the structure override// as it affords you a performance win by allowing you// to initialize some fields of the structure only once,// outside of your insertion loop.
HTREEITEM hPA = m_TreeCtrl.InsertItem(TVIF_TEXT,
_T("Pennsylvania"), 0, 0, 0, 0, 0, hCountry, NULL);
// Insert the "Washington" item and assure that it is// inserted after the "Pennsylvania" item. This override is // more appropriate for conveniently inserting items with // images.
HTREEITEM hWA = m_TreeCtrl.InsertItem(_T("Washington"),
0, 0, hCountry, hPA);
// We'll add some cities under each of the states.// The override used here is most appropriate// for inserting text-only items.
m_TreeCtrl.InsertItem(_T("Pittsburgh"), hPA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Harrisburg"), hPA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Altoona"), hPA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Seattle"), hWA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Kalaloch"), hWA, TVI_SORT);
m_TreeCtrl.InsertItem(_T("Yakima"), hWA, TVI_SORT);
Contains information used to add a new item to a tree-view control. This structure is used with the TVM_INSERTITEM message. The structure is identical to the TV_INSERTSTRUCT structure, but it has been renamed to follow current naming conventions.
TVITEM structure that contains information about the item to add.
Remarks
The unions in this structure have been updated to work with compilers that do not support nameless unions. If your compiler does not support nameless unions, define the NONAMELESSUNION token before including the commctrl.h header file.
Important Using TVI_LAST to insert an item into a tree-view node that already contains a large number of items can take a long time, causing the application to stop responding until the insert operation completes.
Requirements
Minimum supported client
Windows Vista [desktop apps only]
Minimum supported server
Windows Server 2003 [desktop apps only]
Header
Commctrl.h
Unicode and ANSI names
TVINSERTSTRUCTW (Unicode) and TVINSERTSTRUCTA (ANSI)
BOOL Create(
int cx,
int cy,
UINT nFlags,
int nInitial,
int nGrow
);
BOOL Create(
UINT nBitmapID,
int cx,
int nGrow,
COLORREF crMask
);
BOOL Create(
LPCTSTR lpszBitmapID,
int cx,
int nGrow,
COLORREF crMask
);
BOOL Create(
CImageList& imagelist1,
int nImage1,
CImageList& imagelist2,
int nImage2,
int dx,
int dy
);
BOOL Create(
CImageList* pImageList
);
Specifies the type of image list to create.This parameter can be a combination of the following values, but it can include only one of the ILC_COLOR values.
Value
Meaning
ILC_COLOR
Use the default behavior if none of the other ILC_COLOR* flags is specified.Typically, the default is ILC_COLOR4; but for older display drivers, the default is ILC_COLORDDB.
ILC_COLOR4
Use a 4-bit (16 color) device-independent bitmap (DIB) section as the bitmap for the image list.
ILC_COLOR8
Use an 8-bit DIB section.The colors used for the color table are the same colors as the halftone palette.
ILC_COLOR16
Use a 16-bit (32/64k color) DIB section.
ILC_COLOR24
Use a 24-bit DIB section.
ILC_COLOR32
Use a 32-bit DIB section.
ILC_COLORDDB
Use a device-dependent bitmap.
ILC_MASK
Uses a mask.The image list contains two bitmaps, one of which is a monochrome bitmap used as a mask.If this value is not included, the image list contains only one bitmap.See Drawing Images from an Image List for additional information on masked images.
nInitial
Number of images that the image list initially contains.
nGrow
Number of images by which the image list can grow when the system needs to resize the list to make room for new images.This parameter represents the number of new images the resized image list can contain.
nBitmapID
Resource IDs of the bitmap to be associated with the image list.
crMask
Color used to generate a mask.Each pixel of this color in the specified bitmap is changed to black, and the corresponding bit in the mask is set to one.
lpszBitmapID
A string containing the resource IDs of the images.
imagelist1
A reference to a CImageList object.
nImage1
Index of the first existing image.
imagelist2
A reference to a CImageList object.
nImage2
Index of the second existing image.
dx
Offset of the x-axis of the second image in relationship to the first image, in pixels.
dy
Offset of the y-axis of the second image in relationship to the first image, in pixels.
You construct a CImageList in two steps.First, call the constructor and then call Create, which creates the image list and attaches it to the CImageListobject.
댓글을 달아 주세요