Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a CFolderDialog like a CFileDialog 1

Status
Not open for further replies.

nbgoku

Programmer
May 25, 2004
108
US
Is there a CFolderDialog like a CFileDialog

im trying to open a folder in a mfc program, but dont understand if mfc already provides a folder opening option (class) like its file opening option (class - CFileDialog)
 
Depends on what you are trying to do...

Are you trying to scan a folder for files?
Are you checking if a folder exists?

I am not aware of any CFolderDialog class or others like it in MFC.

Tell us what your trying to do and we'll try our best.

-Ron

cout << "If you don't know where you want to go, we'll make sure you get taken";
 
I don't know about a CFolderDialog class, but I think if you use this (copied from MSDN) it should help you get the job done

bdiamond
 
use what bdiamond ?

yah im trying to have the user select a folder that is to be scanned for a certain file, any ideas?
 
sorry, i thought I pasted this in here.

SHBrowseForFolder


Displays a dialog box that enables the user to select a Shell folder.


LPITEMIDLIST SHBrowseForFolder(
LPBROWSEINFO lpbi
);

Parameters
lpbi
[in] Pointer to a BROWSEINFO structure that contains information used to display the dialog box.
Return Values
Returns a pointer to an ITEMIDLIST structure (PIDL) that specifies the location of the selected folder relative to the root of the namespace. If the user chooses the Cancel button in the dialog box, the return value is NULL.

Remarks
You must initialize COM using CoInitializeEx with the COINIT_APARTMENTTHREADED flag on dwCoInit set prior to calling SHBrowseForFolder. You can also use CoInitialize or OLEInitialize, which always use apartment threading.

The calling application is responsible for freeing the returned PIDL with the Shell allocator's IMalloc::Free method. To retrieve a handle to the Shell allocator's IMalloc interface, call SHGetMalloc. See The Shell Namespace for further discussion of the Shell allocator and PIDLs.

There are two styles of dialog box available. The older style is displayed by default, and is not resizable. To specify a new-style dialog box, set the BIF_USENEWUI flag in the ulFlags member of the BROWSEINFO structure. It has a number of additional features, including: drag and drop capability within the dialog box, reordering, shortcut menus, new folders, delete, and other shortcut menu commands. Initially, it is larger than the old dialog box, but can be resized by the user.

If you implement a callback function, you will receive a handle to the dialog box. One use of this window handle is to modify the layout or contents of the dialog box. Because it is not resizable, modifying the old-style dialog box is relatively straightforward. Modifying the new-style dialog box is much more difficult, and not recommended. Not only does it have a different size and layout than the old style, but its dimensions and the positions of its controls change every time it is resized by the user.

If the BIF_RETURNONLYFSDIRS flag is set in the ulFlags member of the BROWSEINFO structure, the OK button will remain enabled for "\\server" items, as well as "\\server\share" and directory items. However, if the user selects a "\\server" item, passing the PIDL returned by the dialog box to SHGetPathFromIDList will fail.

See Also
Open and Save Common Dialog Boxes

Requirements
Version 4.00 and later of Shell32.dll

Windows NT/2000: Requires Windows NT 4.0 or later.
Windows 95/98/Me: Requires Windows 95 or later.
Header: Declared in Shlobj.h.
Import Library: Shell32.lib.

bdiamond
 
Code:
	BROWSEINFO bi = { 0 };
	char path[MAX_PATH];
    bi.ulFlags = BIF_USENEWUI | BIF_UAHINT | BIF_BROWSEINCLUDEFILES | BIF_EDITBOX;
	bi.lpszTitle = "Select File\\Folder";
	bi.pszDisplayName = path;
    LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
    if ( pidl != 0 )
    {
        // get the name of the folder
        ofn = path;
		// free memory used
        IMalloc * imalloc = 0;
        if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
        {
            imalloc->Free ( pidl );
            imalloc->Release ( );
        }
    }

this works fine! but 1 issue, how do i get the hole path to be sent to ofn, i dont want just the last path, i want the hole directory location

for example, for a folder called a in C:\a
ofn would only display a, not C:\a, is tehre a way to display the full path?
 
wait nvm i found out how

Code:
	BROWSEINFO bi = { 0 };
	char fullpath[MAX_PATH];
    bi.ulFlags = BIF_USENEWUI | BIF_UAHINT | BIF_BROWSEINCLUDEFILES | BIF_EDITBOX;
	bi.lpszTitle = "Select File\\Folder";
    LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
    if ( pidl != 0 )
    {
		if (SHGetPathFromIDList(pidl, fullpath))
		{
			ofn = fullpath;
		}
		// free memory used
        IMalloc * imalloc = 0;
        if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
        {
            imalloc->Free ( pidl );
            imalloc->Release ( );
        }
    }

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top