VC6.0

hRootItem = m_ctrlTree.InsertItem ("DiffDBS Search Result", TVI_ROOT, TVI_LAST);
hFileItem = m_ctrlTree.InsertItem (strTmp, hRootItem, TVI_LAST);

m_ctrlTree.InsertItem (strTmp, hRootItem, TVI_LAST);

解释;哈哈,这个够详细:
// Gain a pointer to our tree control

CTreeCtrl* pCtrl = (CTreeCtrl*) GetDlgItem(IDC_TREE1);
ASSERT(pCtrl != 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 = pCtrl->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 = pCtrl->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 = pCtrl->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.

pCtrl->InsertItem(_T("Pittsburgh"), hPA, TVI_SORT);
pCtrl->InsertItem(_T("Harrisburg"), hPA, TVI_SORT);
pCtrl->InsertItem(_T("Altoona"), hPA, TVI_SORT);

pCtrl->InsertItem(_T("Seattle"), hWA, TVI_SORT);
pCtrl->InsertItem(_T("Kalaloch"), hWA, TVI_SORT);
pCtrl->InsertItem(_T("Yakima"), hWA, TVI_SORT);

2)

原来做了个tree控件,用来管理一系列item,可是每次添加item后,需要手动点击“+”号,才能打开树根,看到添加后的结果。就希望在添加一项后,树控件可以自动展开,用到了Expand函数:

   m_ctrlTree.Expand(hRoot,TVE_EXPAND);

//hRoot指定要展开的树根(或子根),参数TVE_EXPAND用来执行展开树hRoot中的所有项。

   哈哈!一句话搞定!现在与大家分享一下。

下面把CTreeCtrl::Expand 函数各参数的功能说明如下:

BOOL Expand( HTREEITEM hItem, UINT nCode );

返回值

Nonzero if successful; otherwise 0.

如果成功则返回非零值;否则返回0。

参数说明

hItem

     Handle of the tree item being expanded.

     要被扩展的tree项的句柄。可以为树根,那么整棵树都被展开。

nCode

     A flag indicating the type of action to be taken. This flag can have one of the following values:

     用来指示要被进行的动作的标志。这个标志可以是下列值之一:

  • TVE_COLLAPSE   Collapses the list.收缩列表。
  • TVE_COLLAPSERESET   Collapses the list and removes the child items.收缩列表并删除子项。
  • TVE_EXPAND   Expands the list.展开列表。
  • TVE_TOGGLE   Collapses the list if it is currently expanded or expands it if it is currently collapsed.如果列表当前是展开的则收缩列表;反之则展开列表。

备注

Call this function to expand or collapse the list of child items, if any, associated with the given parent item.此成员函数用来展开或收缩给定父项的子项列表(如果有)。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值