mfc >> SHBrowseForFolder

by Murrgon » Wed, 26 Jan 2005 06:28:43 GMT

I want to set the pidlRoot member of the BROWSEINFO structure to
a default location. How do I get a PIDL from a path represented
by a text string like this: _T("C:\Program Files")?

Thanks


mfc >> SHBrowseForFolder

by Michael K. O'Neill » Wed, 26 Jan 2005 07:09:05 GMT


I'm not certain about the pidl for an arbitrarily named folder, but if your
real interest is the "Program Files" folder, then you shouldn't use a text
string anyway, since the text is user-selectable and in fact changes based
on language locales.

For "Program Files" and other special folders, you can get the pidl using
the SHGetFolderLocation function, passing in a CSIDL of CSIDL_PROGRAM_FILES.
See
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shgetfolderlocation.asp

Mike









mfc >> SHBrowseForFolder

by Murrgon » Thu, 27 Jan 2005 00:17:38 GMT

Well, actually I am not all that interested in the "Program Files" folder.
I was just using it as an example. Maybe a better example would be, how do
I get the PIDL of _T("F:\WorkingFiles\Resources")?







SHBrowseForFolder

by Murrgon » Thu, 27 Jan 2005 00:28:44 GMT

Well, I did some digging and I found this at code project:

http://www.codeproject.com/file/browsepf.asp

This is what I was looking for.
Thanks







SHBrowseForFolder

by Jeff F » Thu, 27 Jan 2005 00:41:41 GMT




This works for me.


#include "stdafx.h"

#include <string>
#include <comdef.h>

template< typename tIComPtr, HRESULT (STDAPICALLTYPE* tInitFnc)( typename
tIComPtr::Interface** ) >
class RaiiComPtr
{
tIComPtr mCom;
public:
RaiiComPtr():mCom(){ tInitFnc( &mCom ); }

tIComPtr operator->()const{ return mCom; }
tIComPtr IComPtr()const{ return mCom; }
};

class PathPidl
{
typedef RaiiComPtr<IMallocPtr,SHGetMalloc> tMallocPtr;

LPITEMIDLIST mPidl;
public:

PathPidl( const std::string& aPath )
: mPidl( NULL )
{
DWORD lFlags = SFGAO_FOLDER;

SHILCreateFromPath(
std::wstring(aPath.begin(),aPath.end()).c_str(), &mPidl, &lFlags );
}

~PathPidl(){ if( mPidl ) tMallocPtr()->Free( (void*)mPidl ); }

operator LPCITEMIDLIST()const{ return mPidl; }
};


void some browsefnc()
{
PathPidl lPathPidl = PathPidl( "c:\\somePath" );

BROWSEINFO bi;

bi.pidlRoot = lPathPidl;

...
}

Jeff F




Similar Threads

1. How to access password protected shared network drives while traversing the dialog created by using SHBrowseForFolder()

Hi,
i am using SHBrowseForFolder() function to traverse through the local system
drives and shared network drives. But if i select a shared network drive
which is password protected it does not ask for username and password. Due
to which i was unable to traverse the shared drive. Can anybody tell me how
to unable this facility or how to capture the double click of mouse on the
tree shown in Browse For Folder dialog.
Thanks.


2. SHBrowseForFolder warning messages

3. How to access password protected shared network drives while traversing the dialog created by using SHBrowseForFolder()

Hi,
i am using SHBrowseForFolder() function to traverse through the local system
drives and shared network drives. But if i select a shared network drive
which is password protected it does not ask for username and password. Due
to which i was unable to traverse the shared drive. Can anybody tell me how
to unable this facility or how to capture the double click of mouse on the
tree shown in Browse For Folder dialog.
Thanks.


4. How to get full directory path from SHBrowseForFolder()

5. SHBrowseForFolder Subclassing.

I would like to change the name of the "cancel" button.  Is that
possible with Subclassing, Superclassing, etc.?
...Bruce

6. SHBrowseForFolder question

7. SHBrowseForFolder parent window

I'm developing an application in C++ using VS.net. I need a browser to return 
a folder that the user selects. SHBrowseForFolder seems to do the trick in 
most instances. I have one place that it fails. During the 
CWinApp::InitInstance() method the m_hWnd of the main window's parent frame 
window (GetMainWindow()->GetParentFrame()->m_hWnd;) is not setup yet. The 
BrowseInfo::hwndOwner requires it. When I create a CDialog at this point it 
only requires a pointer to the CFrameWnd and it works fine. Any ideas how I 
can get around this? 

Thanks, Neil

8. SHBrowseForFolder and "Application Data" folder