Solved

Iterating Treeview in SHBrowseForFolder Dialog.

Posted on 2007-04-03
5
348 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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