🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Explorer type TreeView in Vista

#240
From: Mehmet Caner
Date: Thu, 17 Jul 2008 12:41
122 lines
4725 bytes
Hi Remy,

Thank you very much for your quick answer.

> You did not say where it is failing.  Can you step through the code and 
> find the particular line that is not working?

The code does not enter the while loop in function FillTree:

//  while (lpeidl->Next(1, &lpidlCurrent, &ulFetched) == S_OK) {

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();
     }
     else ErrorFunc();
    }
    else ErrorFunc();
    lpMalloc->Free(lpidl);
    lpsf->Release();
   }
   else ErrorFunc();
   lpMalloc->Release();
  }
  else ErrorFunc();
}
//---------------------------------------------------------------------------
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) { //////// 
failing line
     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);
    }
    ErrorFunc();
    TreeView1->Items->EndUpdate();

    lpeidl->Release();
   }
   else {
    ErrorFunc();
   }
   lpMalloc->Release();
  }
  else {
 Screen->Cursor = crArrow;
 ErrorFunc();
  }
  Screen->Cursor = crArrow;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ErrorFunc (void)
{
  LPTSTR MsgBuf;

  FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | 
FORMAT_MESSAGE_FROM_SYSTEM, NULL,
     GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
     (LPTSTR) &MsgBuf, 0, NULL);

  MessageBox (NULL, MsgBuf, "Error Message", MB_OK|MB_ICONINFORMATION);
  LocalFree (MsgBuf);
}
//-----------------------------------------------------------------------------

> Have you tried using Vista's new KNOWNFOLDERIDs instead of CSIDLs?  In 
> this case, CSIDL_DRIVES maps to FOLDERID_ComputerFolder.  Have a look at 
> MSDN for more details:
>
>    Known Folders
>    http://msdn.microsoft.com/en-us/library/bb776911(VS.85).aspx

Thanks for the tip. I think it requires Vista SDK. I have download and 
installed it. I have begun studying on KNOWNFOLDERID. 
Technical Details
Message-ID: <487f3e1b@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <487db2ae$1@newsgroups.borland.com> <487e421b$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,d1c1213ec3c3ef45
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
References: <487db2ae$1@newsgroups.borland.com> <487e421b$1@newsgroups.borland.com>
Subject: Re: Explorer type TreeView in Vista
Date: Thu, 17 Jul 2008 15:41:43 +0300
Lines: 124
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
NNTP-Posting-Host: 88.252.13.129
Message-ID: <487f3e1b@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1216298523 88.252.13.129 (17 Jul 2008 05:42:03 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 4569