📄 subject_37926.htm
字号:
<p>
序号:37926 发表者:夏乾坤 发表日期:2003-04-29 14:18:46
<br>主题:关于TREE 控件
<br>内容:bool CFTPFileDlg::GetFileToList(CString filepath)<BR>{<BR> HTREEITEM hTree,rTree;<BR> CFileFind tempFind; <BR> char tempFileFind[200] ={0}; <BR> sprintf(tempFileFind,"%s\\*.*",filepath);<BR><BR> hTree = rTree = m_Tree2.InsertItem(filepath);<BR> //m_Tree2.InsertItem("asdf",rTree);<BR><BR> <BR> BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);<BR> <BR> while(IsFinded)<BR> {<BR> IsFinded=(BOOL)tempFind.FindNextFile();<BR> if(!tempFind.IsDots())<BR> {<BR> char foundFileName[200];<BR> strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));<BR> if(tempFind.IsDirectory())<BR> { <BR> char tempDir[200];<BR> sprintf(tempDir,"%s\\%s",filepath,foundFileName);<BR> GetFileToList(tempDir);<BR> }<BR> else<BR> { <BR> if(dirpath!=filepath && dirpath !="")<BR> { <BR> dirpath = dirpath.Mid(m_Edit5.GetLength()+1);<BR> hTree = m_Tree2.InsertItem(dirpath,rTree);<BR> dirpath = filepath;<BR> }<BR> CString tmp = foundFileName;<BR> m_Tree2.InsertItem(foundFileName,hTree);//我想把这里的文件按照像Windows的目录和文件夹的方式写进来,确没懂这个hTree句柄<BR>//还有怎样将文件夹的图标正确的载入到我的CImageList里面?<BR> }<BR> }<BR> }<BR> return 1;<BR>}
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:wowow 回复日期:2003-04-29 14:46:05
<br>内容:1.树节点的插入:<BR>TV_INSERTSTRUCT tvInsertStruct;<BR>// = NULL表示根节点,=非空值表示在某个节点下插入子节点<BR>tvInsertStruct.hParent = NULL;<BR>// 节点文本内容<BR>tvInsertStruct.item.pszText = sRootItem[i].GetBuffer(sRootItem[i].GetLength());<BR>// 节点内容(图标/选择后的图标/文本)<BR>tvInsertStruct.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT;<BR>// 图标序号<BR>tvInsertStruct.item.iImage = nCurCount;<BR>// 选择后的图标序号<BR>tvInsertStruct.item.iSelectedImage = nCurCount + nItemCount;<BR>// 插入节点并返回该节点<BR>pFirst[i] = tree.InsertItem(&tvInsertStruct);<BR><BR>2.加载节点图标<BR>定义一个成员变量CImageList imageTree;(不能使用临时变量)<BR>// 大小16x16,nTreeCount:节点个数<BR>imageTree.Create(16, 16, ILC_MASK, nTreeCount, 0);<BR>// 设置树的背景色<BR>imageTree.SetBkColor(RGB(255,255,255));<BR>......<BR>CBitmap *pItemTreeBitmap = new CBitmap[nTreeCount];<BR>HICON *pItemTreeIcon = new HICON[nTreeCount];<BR>for (int i = 0; i < nTreeCount; ++i)<BR>{<BR> pItemTreeBitmap[i].LoadBitmap(bitmapTree[i]);<BR> pItemTreeIcon[i] = AfxGetApp()->LoadIcon(iconTree[i]);<BR> // 图标为Bitmap时的加载方式<BR> imageTree.Add(&pItemTreeIcon[i], RGB(255, 255, 255));<BR> // 图标为Icon时的加载方式<BR>// imageTree.Add(pItemListIcon[i]);<BR>}<BR>delete []pItemTreeBitmap;<BR>delete pItemTreeIcon;<BR>// 设置ImageList<BR>m_Tree2.SetImageList(&imageTree, TVSIL_NORMAL);
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -