树型控件(tree control)怎么用?我是初学者,想把如下的内容加到树型控件上:
一个目录为"初中部"下面又有"初一","初二","初三"三个子目录,"初一"目录下
又有"初一(1)班","初一(2)班","初一(3)班",初二、初三也是一样,然后各班
下面是每个以学生名字命名的文件,要求把这些逐级加到树型控件上,最下面的一
级是文件名,怎么做?
一个目录为"初中部"下面又有"初一","初二","初三"三个子目录,"初一"目录下
又有"初一(1)班","初一(2)班","初一(3)班",初二、初三也是一样,然后各班
下面是每个以学生名字命名的文件,要求把这些逐级加到树型控件上,最下面的一
级是文件名,怎么做?
解决方案 »
- #include <windows.h>多余的问题
- VC++如何用一个button实现:打开文件选择对话框,选择文件的动作
- (60分)[求助]WindowProc和DeviceIoControl禁用优盘USB口问题。。。
- 获取打印份数总为1?
- 在对话框程序中,怎样实现拖动一个控件,主窗口跟着被拖动,就像拖动标题栏一样效果?
- 【LOOK!】你想知道怎写毒病吗.你想知道怎么反垃圾邮件吗?...(内详)
- 如何写一个不能被继承的类?
- 如何在Dialog 中load BMP文件后仍显示被图片遮掉的控件?
- MFC写的Player数据采集器器,打开创建Excel时提示找不到“Templates.xls”,求大神指导
- 有关剪贴版的hteml格式以及htmlview,哈哈76大分,快抢阿!
- 错误连篇,不知错在哪里!
- 简单问题,FTP获取文件列表的问题,答对立刻给分,up也沾光.
不过是英文的。
HTREEITEM h2=m_tree.InsertItem("初一",h1);
HTREEITEM h3=m_tree.InsertItem("初一(1)班",h2);
m_tree.InsertItem("YourName",h3);
tvis.hParent = TVI_ROOT;
tvis.hInsertAfter = TVI_LAST;
tvis.item.mask = TVIF_TEXT | TVIF_PARAM;
tvis.item.pszText = "Root";
tvis.item.lParam = 0;
HTREEITEM hTreeItemRoot = m_ctlTree.InsertItem(&tvis);
tvis.hParent = hTreeItemRoot;
tvis.item.pszText = "000001";
tvis.item.lParam = 1;
m_ctlTree.InsertItem(&tvis);
tvis.item.pszText = "000002";
tvis.item.lParam = 2;
m_ctlTree.InsertItem(&tvis);
tvis.item.pszText = "000003";
tvis.item.lParam = 3;
m_ctlTree.InsertItem(&tvis);
m_ctlTree.SelectItem(hTreeItemRoot);
m_ctlTree.Expand(hTreeItemRoot, TVE_EXPAND);
TCItem.hParent=TVI_ROOT;
TCItem.hInsertAfter=TVI_LAST;
TCItem.item.mask=TVIF_TEXT;
TCItem.item.pszText="初中部";
hCZB=InsertItem(&TCItem);TCItem.hParent=hCZB;
TCItem.item.pszText="初一";
hC1=InsertItem(&TCItem);
TCItem.item.pszText="初二";
hC2=InsertItem(&TCItem);
TCItem.item.pszText="初三";
hC3=InsertItem(&TCItem);TCItem.hParent=hC1;
TCItem.item.pszText="初一(1)班";
hC1Class1=InsertItem(&TCItem);CString str;
str="你的学生资料目录\\*.dat";
char pszText[255];CFileFind finder;BOOL bWorking = finder.FindFile(str);
while (bWorking)
{
bWorking = finder.FindNextFile(); TCItem.hParent=hC1Class1;
strcpy(pszText,finder.GetFileTitle());
TCItem.item.pszText=pszText;
InsertItem(&TCItem);
}finder.Close();
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);