Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Iterating Treeview in SHBrowseForFolder Dialog.

Posted on 2007-04-03
5
Medium Priority
?
357 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

650 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