🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #229

Explorer type TreeView in Vista

#229
From: Mehmet Caner
Date: Wed, 16 Jul 2008 08:34
91 lines
3540 bytes
Hi,

The following code fills TreeView1 component with the drives of the computer 
in Windows XP SP2 successfully, but failed in Vista. What's wrong with the 
code?

Thanks in advance!

void __fastcall TForm1::FirstTree(void)
{
  LPMALLOC lpMalloc;

  if (SUCCEEDED(SHGetMalloc(&lpMalloc))) {
  LPSHELLFOLDER lpsf;
  SHFILEINFO FileInfo;
  unsigned int uSHFlags = SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | 
SHGFI_PIDL;
  TTreeNode *TNode;

  if (SUCCEEDED(SHGetDesktopFolder(&lpsf))) {
   LPITEMIDLIST lpidl;
   if (SUCCEEDED(SHGetFolderLocation(Handle, CSIDL_DRIVES, NULL, 0, 
&lpidl))) {
     LPSHELLFOLDER lpsfSub;
     if (SUCCEEDED(lpsf->BindToObject(lpidl, NULL, IID_IShellFolder, 
reinterpret_cast<void **>(&lpsfSub)))) {
      SHGetFileInfo((LPCSTR)lpidl, 0, &FileInfo, sizeof(SHFILEINFO), 
uSHFlags);
      FillTree(lpsfSub, lpidl);
      lpsfSub->Release();
     }
   }
   lpMalloc->Free(lpidl);
   lpsf->Release();
  }
  lpMalloc->Release();
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FillTree (LPSHELLFOLDER lpsf, LPITEMIDLIST lpidl)
{
  LPMALLOC lpMalloc;
  Screen->Cursor = crHourGlass;

  if (SUCCEEDED(SHGetMalloc(&lpMalloc))) {
   LPENUMIDLIST lpeidl;
   HRESULT HRes;

   HRes = lpsf->EnumObjects(NULL, SHCONTF_NONFOLDERS, &lpeidl);

   if (HRes == NOERROR) {
    TreeView1->Items->BeginUpdate();
    LPITEMIDLIST lpidlCurrent;
    unsigned long ulFetched;
    while (lpeidl->Next(1, &lpidlCurrent, &ulFetched) == S_OK) {
     LPITEMIDLIST lpidlFQ = MergeIDLists (lpMalloc, lpidl, lpidlCurrent);
     if (lpidlFQ) {
      SHFILEINFO FileInfo;
      DWORD FileAttrib;
      unsigned int uSHFlags;
      TTreeNode *Node;
      uSHFlags = SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | SHGFI_PIDL;
      SHGetFileInfo(reinterpret_cast<LPCSTR>(lpidlFQ), FileAttrib, 
&FileInfo, sizeof(SHFILEINFO), uSHFlags);

      Node = TreeView1->Items->AddChild(NULL, FileInfo.szDisplayName);
      Node->ImageIndex = FileInfo.iIcon;
      Node->SelectedIndex = FileInfo.iIcon;
      Node->Data = reinterpret_cast<void *>(lpidlFQ);
      TTreeNode *ChildNode = TreeView1->Items->AddChild(Node, "");
      ChildNode->ImageIndex = -1;
     }
     lpMalloc->Free(lpidlCurrent);
    }
    TreeView1->Items->EndUpdate();

    lpeidl->Release();
   }
   else {
    ShowMessage ("Error Code: 001");
   }
   lpMalloc->Release();
  }
  else {
 Screen->Cursor = crArrow;

 ShowMessage ("Error Code: 002");
  }
  Screen->Cursor = crArrow;
}
//---------------------------------------------------------------------------
Technical Details
Message-ID: <487db2ae$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!news.isoc.lu!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d1c1213ec3c3ef45,start
X-Google-Attributes: gid10cc67,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mehmet Caner" <mcaner40@hotmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Explorer type TreeView in Vista
Date: Wed, 16 Jul 2008 11:34:45 +0300
Lines: 93
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
NNTP-Posting-Host: 88.232.217.66
Message-ID: <487db2ae$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1216197294 88.232.217.66 (16 Jul 2008 01:34:54 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!news.isoc.lu!newsgroups.borland.com!not-for-mail