I have a windows application written in C++. The application generates certain configuration files in a hidden directory. I want to give user an option to open that directory from my application. Clicking that option should open a windows explorer like dialog with an input directory location. I spend time searching for a similar api, but end up with certain dialogs like "DlgDirListComboBoxW" or "GetOpenFileName" or "GetSaveFileName". I am looking for an api to open normal Windows explorer like Dialog with an input directory location. It would be really helpful if the api belongs to CommonDialogs section.
Showing a Windows Explorer Dialog from a C++ application
1.1k Views Asked by aksjain At
2
There are 2 best solutions below
0
On
You can use the SHBrowseForFolder
It shows a dialog similar to this:

This is a example for how to use it:
BOOL GetFolder(LPCSTR folderpath,
LPCSTR szCaption,
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;
}
How about:
You can set
hWndOwnerto your main window handle if you're so inclined and can choose from a variety of other options.For more information and usage details, check out the MSDN page on
ShellExecute.