| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 736 人关注过本帖
标题:网上邻居目录树
只看楼主 加入收藏
niekui
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2005-4-16
收藏
 问题点数:0 回复次数:4 
网上邻居目录树
#include <vcl.h> #pragma hdrstop #include "Unit1.h" //#include <shlobj.h> #include <shellapi.h> #include <stdio.h> //-------------------------------------------------------------------------- - #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; TImageList *List; LPMALLOC mem; //-------------------------------------------------------------------------- - __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { LPSHELLFOLDER desk; LPITEMIDLIST net; SHFILEINFO fi; STRRET nome; char scom[255]; TTreeNode *n; TDir * d; List = new TImageList(this); List->ShareImages = true; List->Handle = SHGetFileInfo("",0,&fi,sizeof(SHFILEINFO),SHGFI_SMALLICON|SHGFI_SYSICONINDEX ); TreeView->Images = List; SHGetMalloc(&mem); SHGetDesktopFolder(&desk); SHGetSpecialFolderLocation(NULL,CSIDL_NETWORK ,&net); desk->GetDisplayNameOf(net,SHGDN_NORMAL ,&nome); GetNome(&nome,net,scom); SHGetFileInfo((LPCSTR)net,0,&fi,sizeof(SHFILEINFO),SHGFI_PIDL|SHGFI_SYSICONI NDEX|SHGFI_DISPLAYNAME |SHGFI_ATTRIBUTES|SHGFI_TYPENAME ); n=TreeView->Items->Add(NULL,scom); n->ImageIndex = fi.iIcon; n->StateIndex = fi.iIcon; n->SelectedIndex = fi.iIcon; d=new TDir; d->ParentShellFolder = desk; d->pidl = net; d->ppidl = net; d->Sfogliato = true; n->Data = d; BrowseFolder(desk,net,net,n); } //-------------------------------------------------------------------------- - void __fastcall TForm1::BrowseFolder(LPSHELLFOLDER padre, LPITEMIDLIST pidl,LPITEMIDLIST ppidl,TTreeNode *nodo) { TTreeNode *c; if(nodo != NULL) { while(nodo->Count > 0) nodo->Item[0]->Delete(); } if(padre!= NULL) { LPSHELLFOLDER ShellFolder=NULL; padre->BindToObject(pidl,NULL,IID_IShellFolder ,(void **)&ShellFolder); if(ShellFolder != NULL) { LPENUMIDLIST enumlist=NULL; ShellFolder->EnumObjects(NULL,SHCONTF_FOLDERS|SHCONTF_INCLUDEHIDDEN ,&enumlist); if(enumlist != NULL) { int i; LPSTRRET nome ; LPITEMIDLIST idfiglio; LPITEMIDLIST pp; char scom[255]; SHFILEINFO fi; TDir *d; int r; int conta1,conta2; enumlist->Reset(); while(enumlist->Next(1,&idfiglio,NULL)!=S_FALSE) { LPITEMIDLIST lpNew = MergeIDList(ppidl,idfiglio); if(!idfiglio) break; if(lpNew== NULL) continue; nome = (LPSTRRET)mem->Alloc(sizeof (STRRET)); memset(&fi,0,sizeof(SHFILEINFO)); r=SHGetFileInfo((LPCSTR)lpNew,0,&fi,sizeof(fi),SHGFI_PIDL|SHGFI_SYSICONINDEX |SHGFI_DISPLAYNAME |SHGFI_ATTRIBUTES|SHGFI_TYPENAME|SHGFI_SMALLICON ); ZeroMemory(nome,sizeof(STRRET)); nome->uType = STRRET_CSTR; ShellFolder->GetDisplayNameOf(idfiglio,SHGDN_NORMAL ,nome); GetNome(nome,idfiglio,scom); c=TreeView->Items->AddChild(nodo,scom); c->ImageIndex = fi.iIcon; c->StateIndex = fi.iIcon; c->SelectedIndex = fi.iIcon; // Cre elelemnto fittizio if(fi.dwAttributes & SFGAO_HASSUBFOLDER) TreeView->Items->AddChild(c,"PP"); d = new TDir; d->ParentShellFolder = ShellFolder; d->pidl = idfiglio; d->ppidl = lpNew; d->Sfogliato = false; c->Data = d; } enumlist->Release(); } } } } void __fastcall TForm1::GetNome(LPSTRRET nome, LPITEMIDLIST id, char * display) { LPSTR lpsz; int cch; switch (nome->uType) { case STRRET_WSTR: cch = WideCharToMultiByte( CP_ACP, 0, nome->pOleStr, -1, NULL, 0, NULL, NULL); lpsz = (LPSTR) mem->Alloc(cch); if (lpsz != NULL) { WideCharToMultiByte( CP_ACP, 0, nome->pOleStr, -1, lpsz, cch, NULL, NULL); sprintf(display,"%s", lpsz); mem->Free(lpsz); } break; case STRRET_OFFSET: sprintf(display,"%s", ((char *) id) + nome->uOffset); break; case STRRET_CSTR: sprintf(display,"%s", nome->cStr); break; } } LPITEMIDLIST __fastcall TForm1::MergeIDList(LPITEMIDLIST a, LPITEMIDLIST b) { int cb1, cb2; if (a) cb1 = GetPIDLSize(a); if (cb1) cb1 = cb1 - 2; if (b) cb2 = GetPIDLSize(b); if (cb2) cb2 = cb2 - 2; int total_size = cb1 + cb2 + 2; LPITEMIDLIST lpidlNew; if(!a || !b) return NULL; lpidlNew = (LPITEMIDLIST)mem->Alloc(total_size); if (lpidlNew) { ZeroMemory(lpidlNew, total_size); CopyMemory(lpidlNew, a, cb1); CopyMemory(((LPBYTE)lpidlNew) + cb1, b, cb2); FillMemory(((LPBYTE)lpidlNew) + cb1 + cb2, 2, 0); return lpidlNew; } return NULL; } int __fastcall TForm1::GetPIDLSize(LPITEMIDLIST lpidl) { unsigned short cb = 0; while (lpidl) { cb = (unsigned short)(cb + lpidl->mkid.cb); lpidl = GetNextItem(lpidl); } return (unsigned short)(cb + 2); } LPITEMIDLIST __fastcall TForm1::GetNextItem(LPITEMIDLIST pidl) { unsigned short nLen = pidl->mkid.cb; if (nLen == 0) return NULL; return (LPITEMIDLIST)((LPBYTE)pidl + nLen); } void __fastcall TForm1::TreeViewExpanding(TObject *Sender, TTreeNode *Node, bool &AllowExpansion) { TDir *d; if(Node != NULL) { d = (TDir *)Node->Data; if(!d->Sfogliato) { BrowseFolder(d->ParentShellFolder,d->pidl,d->ppidl,Node); } d->Sfogliato = true; } } //-------------------------------------------------------------------------- - void __fastcall TForm1::TreeViewClick(TObject *Sender) { TDir *d; if(TreeView->Selected) { char scom[MAX_PATH]; d=(TDir *)(TreeView->Selected->Data); SHGetPathFromIDList(d->ppidl,scom); Label1->Caption = scom; } }
搜索更多相关主题的帖子: 网上邻居 目录 
2005-04-16 10:55
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
慢着,这段代码是delphi的吧?
2005-04-16 11:15
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
实现的功能是很诱人,但是没写注释,VCL的代码看不懂啊。
2005-04-16 11:15
tjl2006tjl
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2004-12-16
收藏
得分:0 
看不懂,能告诉我这是干吗用的啊?

2005-04-16 11:49
musicml
Rank: 1
等 级:新手上路
帖 子:273
专家分:0
注 册:2005-4-2
收藏
得分:0 
以下是引用tjl2006tjl在2005-4-16 11:49:19的发言: 看不懂,能告诉我这是干吗用的啊?

Every thing is possible.
2005-04-16 16:20
快速回复:网上邻居目录树
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025196 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved