RE: Push button in a dialog box for exploring path.
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
#include "shlobj.h"
#include <string>
bool GetFolder(std::string& folderpath,
const char* szCaption = NULL,
HWND hOwner = NULL)
{
bool retVal = false;
// The BROWSEINFO struct tells the shell
// how it should display the dialog.
BROWSEINFO bi;
memset(&bi, 0, sizeof(bi));
bi.ulFlags = BIF_USENEWUI;
bi.hwndOwner = hOwner;
bi.lpszTitle = szCaption;
// must call this if using BIF_USENEWUI
::OleInitialize(NULL);
// Show the dialog and get the itemIDList for the
// selected folder.
LPITEMIDLIST pIDL = ::SHBrowseForFolder(&bi);
if(pIDL != NULL)
{
// Create a buffer to store the path, then
// get the path.
char buffer[_MAX_PATH] = {'\0'};
if(::SHGetPathFromIDList(pIDL, buffer) != 0)
{
// Set the string value.
folderpath = buffer;
retVal = true;
}
// free the item id list
CoTaskMemFree(pIDL);
}
::OleUninitialize();
return retVal;
}
/////////////////////////////////////////////////////////////////////////////
// CDialogCreateVolume message handlers
void CDialogCreateVolume::OnCreatVolumePath()
{
CString folderPath;
std::string szPath("");
if (GetFolder(szPath, "Select a folder.") == true)
{
folderPath = CString (szPath.c_str());
MessageBox(folderPath);
}
else
{
MessageBox("No folder selected!\n");
}
}
"Daum" wrote:
My dialog box has a combo box that gets a path string from key board input.
Also, the dialog box has a push button that pop-ups browsing folder dialog
so that users can select a path using a mouse instead of key board input.
Q) How to make pop-up the browsing folders? I believe the "browsing folder"
dialog is already built in by MFC.
Q) Also, how to get the user selection from the pop-ups browsing folders?
Thank you so much for the help.
- Daum