Network Neighborhood Directory tree

Source: Internet
Author: User
Tags addchild sprintf

//--------------------------------------------------------------------------


-


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


}


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.