Is there an equivalent class to CFileDialog for directories 
Author Message
 Is there an equivalent class to CFileDialog for directories

CFileDialog is a class to let the user specify
a file that is to be open or saved. I need a similar
class letting the user specify a directory path.
How do I do that? Is there any MFC class that I can use?



Mon, 31 Jul 2000 03:00:00 GMT  
 Is there an equivalent class to CFileDialog for directories

No there isn't (unfortunately).  If your using Win32 (95/NT), you can use
SHBrowseForFolder().  It's a nice tree style folder selection dialog.

--
Douglas Peterson
Software Engineer
Telex Communications, Inc
(For E-mail reply, remove the *'s)


Quote:

>CFileDialog is a class to let the user specify
>a file that is to be open or saved. I need a similar
>class letting the user specify a directory path.
>How do I do that? Is there any MFC class that I can use?



Mon, 31 Jul 2000 03:00:00 GMT  
 Is there an equivalent class to CFileDialog for directories

There is a Directory Picker sample on the MSDN CD.  You can also use the
shell folder browser interface to just select folders like in the Find
command under Win 95 or NT 4.0.   A routine to do that look like this:

To use this stuff just implement the following then call FolderBrowser()
with the following parameters:

BOOL FolderBrowser( CWnd *pWnd, CString& title, CString& dir, CString
&initial )

pWnd = pointer to parent window (typically "this")
title = title for the folder browser window
dir = place to put the resulting folder path
initial = place to start the initial tree (full path) browser opens to
this path

Include all of this code:

HTH,

Tom

#include "stdafx.h"
#include <direct.h>
// All these include files are required!
#include <winsock.h>
#include <nspapi.h>
#include <winnetwk.h>
#include <shlobj.h>
#include <winnls.h>

// SetSelProc
// Callback procedure to set the initial selection of the browser.
int CALLBACK SetSelProc( HWND hWnd, UINT uMsg, LPARAM lParam, LPARAM
lpData ) {
        if (uMsg==BFFM_INITIALIZED) {
            ::SendMessage( hWnd, BFFM_SETSELECTION, TRUE, lpData );
        }
        return 0;

Quote:
}

// FolderBrowswer
// Display a folder browser allowing the user to browse for a directory.

BOOL FolderBrowser( CWnd *pWnd, CString& title, CString& dir, CString
&initial )
{
 BOOL r = FALSE;
 LPMALLOC pMalloc;
 char buffer[MAX_PATH]; // Retrieve the task memory allocator.
 if (SUCCEEDED(::SHGetMalloc(&pMalloc))) {
 // Fill in a BROWSEINFO structure, setting the flag toindicate
 // that we are only interested in file systemdirectories.
  BROWSEINFO bi;
  bi.hwndOwner = pWnd->GetSafeHwnd();
  bi.pidlRoot = NULL;
  bi.pszDisplayName = buffer;
  bi.lpszTitle = (LPCSTR) title;
  bi.ulFlags = BIF_RETURNONLYFSDIRS;
  bi.lpfn = NULL;
  bi.iImage = 0;
  bi.lpfn = SetSelProc;
  bi.lParam = (LPARAM)(LPCSTR)initial;
  // Display the browser.
  ITEMIDLIST * item_list =  ::SHBrowseForFolder(&bi);
  // If the user selected a folder...
  if (item_list) {
   // Convert the item ID to a pathname, and copy it to the
   // out parameter.
   if (::SHGetPathFromIDList(item_list, buffer)) {
    dir = buffer;
    if(dir.Right(1) != "\\")
     dir += "\\";
             r = TRUE;
   }
   // Free the PIDL allocated by SHBrowseForFolder
         pMalloc->Free(item_list);
  } // Release the shell's allocator
  pMalloc->Release();
 }
 return r;

Quote:
}

> CFileDialog is a class to let the user specify
> a file that is to be open or saved. I need a similar
> class letting the user specify a directory path.
> How do I do that? Is there any MFC class that I can use?



Mon, 31 Jul 2000 03:00:00 GMT  
 Is there an equivalent class to CFileDialog for directories

Assuming Windows 95 or NT4.0 you can use SHBrowseForFolder()

It's a bit of a pain, maybe using SHGetPathFromIDList to figure out what was
returned.
see #include "shlobj.h"


Quote:

>CFileDialog is a class to let the user specify
>a file that is to be open or saved. I need a similar
>class letting the user specify a directory path.
>How do I do that? Is there any MFC class that I can use?



Mon, 31 Jul 2000 03:00:00 GMT  
 Is there an equivalent class to CFileDialog for directories

http://chat.carleton.ca/~sofori

a CTreeCtrl derived class that automatically fills the tree with shell
folders

Quote:

> CFileDialog is a class to let the user specify
> a file that is to be open or saved. I need a similar
> class letting the user specify a directory path.
> How do I do that? Is there any MFC class that I can use?



Wed, 02 Aug 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Directory/Folder equivalent of CFileDialog???

2. I am not able to see my database class members in class view - Please help

3. In which directory am I ??

4. CFileDialog Initial Directory problems

5. CFileDialog but than for selecting a directory

6. Using CFileDialog to select directories

7. CFileDialog: select a directory?

8. seting default directory in CFileDialog

9. CFileDialog - is it possible to select a directory?

10. Current directory for CFileDialog?

11. CFileDialog - Resetting Directory After Use

12. CFileDialog to select a directory

 

 
Powered by phpBB® Forum Software