Solved

Iterating Treeview in SHBrowseForFolder Dialog.

Posted on 2007-04-03
5
341 Views
Last Modified: 2010-04-05
I need to remove non-fixed drives in a SHBrowseForFolder dialog. I am passing the handle
to the treeview from an EnumChildProc that is called in the BrowseDialogCallBack.

type
  Params  = packed record
    LocalDrives:    bool;
    pidlRoot:       PItemIDList;
    BffInitialized: bool;
    hWndTreeCtrl:   hwnd;
    hWndEditCtrl:   hwnd;
    InitialFolder:  pchar;
    SelectedItem:   htreeitem;
    SelectedPath:   array[0..MAX_PATH] of char;
  end;

var
  BffParams:  Params;

procedure TVLocalDrives (hwnd: hwnd);
var
  hti, child:         htreeitem;
  htiText:            array[0..MAX_PATH] of char;
  TVI:                tagTVItem;
  Count, DriveType:   uint;
begin
    hti := TreeView_GetRoot(BffParams.hWndTreeCtrl);
    TVI.mask        := TVIF_HANDLE or TVIF_TEXT or TVIF_CHILDREN or TVIF_STATE or TVIF_PARAM;
    TVI.hItem       := hti;
    TVI.pszText     := htiText;
    TVI.cchTextMax  := MAX_PATH;
    TreeView_GetItem(BffParams.hWndTreeCtrl, TVI);

    child := TreeView_GetChild(BffParams.hWndTreeCtrl, hti);
    //Build TreeViewItem Structure used to retrieve text of selected item.
    TVI.mask        := TVIF_HANDLE or TVIF_TEXT or TVIF_CHILDREN or TVIF_STATE or TVIF_PARAM;
    TVI.hItem       := child;
    TVI.pszText     := htiText;
    TVI.cchTextMax  := MAX_PATH;
    TreeView_GetItem(BffParams.hWndTreeCtrl, TVI);

    While hti <> nil do
    begin
      TVI.hItem     := hti;
      TreeView_GetItem(BffParams.hWndTreeCtrl, TVI);
      DriveType := GetDriveType(pchar(leftstr(string(TVI.pszText),3)));
      if DriveType <> DRIVE_FIXED then
      begin
        //TreeView_DeleteItem(BffParams.hWndTreeCtrl, TVI.hItem);
      end;

      hti := TreeView_GetNextItem(BffParams.hWndTreeCtrl, TVI.hItem, TVGN_NEXT);
    end;
end;

This isn't working, the call:
    child := TreeView_GetChild(BffParams.hWndTreeCtrl, hti);
does not return a child.

I have verified that the the Root is 'My Computer'.

Does it look like I'm doing anything else wrong?
0
Comment
Question by:EddieShipman
  • 2
5 Comments
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 18845309
     Hi!

Try to change
TreeView_GetItem(BffParams.hWndTreeCtrl, TVI);
to
hti := TreeView_GetItem(BffParams.hWndTreeCtrl, TVI);

Regards,
   Tomas Helgi
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 18845628
The TreeView_GetItem macro modifies the TVI parameter and returns
a BOOLEAN.
0
 
LVL 26

Accepted Solution

by:
EddieShipman earned 0 total points
ID: 18846290
I think we've figured out what the problem is.
When we first enter the callback, the only item IS
My Computer or the passed root.

Other items are not immediately available which means that we can't
iterate through the items.

Guess we'll have to blow this off for now...
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question