- LPTSTR lpBuffer;
-// LPITEMIDLIST pidlPrograms; // PIDL for Programs folder
- LPITEMIDLIST pidlBrowse; // PIDL selected by user
- LPMALLOC pMalloc = NULL;
-
- HRESULT result = ::SHGetMalloc(&pMalloc);
-
- if (result != NOERROR)
- return wxID_CANCEL;
-
- // Allocate a buffer to receive browse information.
- if ((lpBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH)) == NULL)
+ bi.hwndOwner = parent ? GetHwndOf(parent) : NULL;
+ bi.pidlRoot = NULL;
+ bi.pszDisplayName = NULL;
+#ifdef __WXWINCE__
+ bi.lpszTitle = m_message.mb_str();
+#else
+ bi.lpszTitle = m_message.c_str();
+#endif
+ bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
+ bi.lpfn = BrowseCallbackProc;
+ bi.lParam = (LPARAM)m_path.c_str(); // param for the callback
+
+ static const int verComCtl32 = wxApp::GetComCtl32Version();
+
+ // we always add the edit box (it doesn't hurt anybody, does it?) if it is
+ // supported by the system
+ if ( verComCtl32 >= 471 )
+ {
+ bi.ulFlags |= BIF_EDITBOX;
+ }
+
+ // to have the "New Folder" button we must use the "new" dialog style which
+ // is also the only way to have a resizable dialog
+ //
+ // "new" style is only available in the version 5.0+ of comctl32.dll
+ const bool needNewDir = HasFlag(wxDD_NEW_DIR_BUTTON);
+ if ( (needNewDir || HasFlag(wxRESIZE_BORDER)) && (verComCtl32 >= 500) )
+ {
+ if (needNewDir)
+ {
+ bi.ulFlags |= BIF_NEWDIALOGSTYLE;
+ }
+ else
+ {
+ // Versions < 600 doesn't support BIF_NONEWFOLDERBUTTON
+ // The only way to get rid of the Make New Folder button is use
+ // the old dialog style which doesn't have the button thus we
+ // simply don't set the New Dialog Style for such comctl versions.
+ if (verComCtl32 >= 600)
+ {
+ bi.ulFlags |= BIF_NEWDIALOGSTYLE;
+ bi.ulFlags |= BIF_NONEWFOLDERBUTTON;
+ }
+ }
+ }
+
+ // do show the dialog
+ LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
+
+ if ( bi.pidlRoot )
+ {
+ ItemListFree((LPITEMIDLIST)bi.pidlRoot);
+ }
+
+ if ( !pidl )