Link to home
Start Free TrialLog in
Avatar of Eddie Shipman
Eddie ShipmanFlag for United States of America

asked on

Iterating Treeview in SHBrowseForFolder Dialog.

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?
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

     Hi!

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

Regards,
   Tomas Helgi
Avatar of Eddie Shipman

ASKER

The TreeView_GetItem macro modifies the TVI parameter and returns
a BOOLEAN.
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial