다음을 통해 공유


CTreeCtrl::InsertItem

트리 뷰 컨트롤에 새 항목을 삽입 하려면이 함수를 호출 합니다.

HTREEITEM InsertItem(
   LPTVINSERTSTRUCT lpInsertStruct 
);
HTREEITEM InsertItem(
   UINT nMask,
   LPCTSTR lpszItem,
   int nImage,
   int nSelectedImage,
   UINT nState,
   UINT nStateMask,
   LPARAM lParam,
   HTREEITEM hParent,
   HTREEITEM hInsertAfter 
);
HTREEITEM InsertItem(
   LPCTSTR lpszItem,
   HTREEITEM hParent = TVI_ROOT,
   HTREEITEM hInsertAfter = TVI_LAST 
);
HTREEITEM InsertItem(
   LPCTSTR lpszItem,
   int nImage,
   int nSelectedImage,
   HTREEITEM hParent = TVI_ROOT,
   HTREEITEM hInsertAfter = TVI_LAST
);

매개 변수

  • lpInsertStruct
    에 대 한 포인터는 TVINSERTSTRUCT 삽입 될 트리 뷰 항목의 특성을 지정 합니다.

  • nMask
    특성 집합을 지정 하는 정수입니다.참조는 TVITEM 의 구조는 Windows SDK.

  • lpszItem
    주소 항목의 텍스트를 포함 하는 문자열입니다.

  • nImage
    항목의 이미지를 이미지 목록 tree view 컨트롤의 인덱스입니다.

  • nSelectedImage
    트리 뷰 컨트롤의 이미지 목록에서 이미지를 선택 하는 항목의 인덱스입니다.

  • nState
    항목의 상태에 대 한 값을 지정합니다.참고 트리 보기 제어 항목 상태를 Windows SDK 적절 한 목록에 대 한.

  • nStateMask
    상태를 설정할 수를 지정 합니다.참조는 TVITEM 의 구조는 Windows SDK.

  • lParam
    32 비트 응용 프로그램 특정 항목과 연결 된 값입니다.

  • hParent
    핸들 삽입 된 항목의 부모입니다.

  • hInsertAfter
    새 항목이 삽입 되는 후 항목의 핸들입니다.

반환 값

성공한 경우 새 항목의 핸들입니다. 그렇지 않으면 NULL.

설명

이 예제에서 각 버전의 함수를 사용 하 여 트리 컨트롤 항목을 삽입 하려는 경우.

예제

// 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);

요구 사항

헤더: afxcmn.h

참고 항목

참조

CTreeCtrl 클래스

계층 구조 차트

CTreeCtrl::DeleteItem

CTreeCtrl::HitTest

CTreeCtrl::SelectDropTarget

CTreeCtrl::GetItem

Tree View Control Reference