Solved

Iterating Treeview in SHBrowseForFolder Dialog.

Posted on 2007-04-03
5
333 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 24

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now