当前位置:七道奇文章资讯编程技术VC/C++编程
日期:2011-03-22 13:54:00  来源:本站整理

网上邻人目录树[VC/C++编程]

赞助商链接



  本文“网上邻人目录树[VC/C++编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

//--------------------------------------------------------------------------
-
#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;
}
}


  以上是“网上邻人目录树[VC/C++编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
  • 在Ubuntu 12.04安装和设置Samba实现网上邻人同享
  • 教大家开启Windows系统网上邻人的FTP功效
  • Win XP下桌面上的"网上邻人"图标没有了怎么恢复
  • 教大家简单清理Windows网上邻人的登陆帐号
  • 在WINDOWS下找不到网上邻人的几种有效办理办法
  • 办理网上邻人无本地衔接办法
  • 网上邻人目录树
  • 办理网上邻人不能拜候的小本领
  • 拜候主机 网上邻人提醒要求输密码
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .