Re: Push button in a dialog box for exploring path.
Daum ha scritto:
I used the way below which are from internet and it works.
But I don't know if it is the best way.
Thanks
-Daum
A problem I see in the code you posted is that it is not Unicode-aware.
The problem is that std::string and 'char' buffers are used, instead the
code should use string and buffers based on TCHAR (which expands to
'char' in ANSI/MBCS builds, and to 'wchar_t' in Unicode builds).
So, your code will fail to compile in Unicode builds (which should be
the standard in these days).
#include "shlobj.h"
#include <string>
bool GetFolder(std::string& folderpath,
const char* szCaption = NULL,
HWND hOwner = NULL)
The prototype of the function may be corrected to something like this
(using CString instead of 'std::string', and TCHR instead of 'char'):
bool GetFolder( CString & folderpath,
const TCHAR * szCaption = NULL,
HWND hOwner = NULL)
> [...]
if(pIDL != NULL)
{
// Create a buffer to store the path, then
// get the path.
char buffer[_MAX_PATH] = {'\0'};
A TCHAR should be used above:
TCHAR buffer[...
/////////////////////////////////////////////////////////////////////////////
// CDialogCreateVolume message handlers
void CDialogCreateVolume::OnCreatVolumePath()
{
CString folderPath;
std::string szPath("");
Just use CString above (no need for std::string):
CString folderPath;
if (GetFolder(szPath, "Select a folder.") == true)
Use _T() for string literal decorations (or just store strings in string
table):
if ( GetFolder(folderPath, _T("Select a folder.") )
...
HTH,
Giovanni