Advertisement

Choose Directory

Started by December 30, 2002 06:33 PM
3 comments, last by mdias 21 years, 10 months ago
Hi, I know my question is not about game developement but how do I open a DialogBox to choose a directory ? I''m talking about choosing a directory just like in winam* when we choose the skins directory. thanx KaMiKaZe
for Windows?

the following funcs will work if you just want the folder name of your "skin", e.g., you know what the root directory will be and want to force the user to stay in the root folder. btw, szRoot needs to be a fullpath.

  #include <shlobj.h>bool MyShellFuncs::FolderSelect( HWND hWnd, LPCSTR szRoot, LPCSTR szPrompt, LPSTR szFolder ){    BROWSEINFO bi;    bool       bRet = false;    bi.hwndOwner      = hWnd;    bi.pidlRoot       = GetFolderPIDL(hWnd, szRoot);    bi.pszDisplayName = szFolder;    bi.lpszTitle      = szPrompt;    bi.ulFlags        = BIF_DONTGOBELOWDOMAIN;    bi.lpfn           = NULL;    bi.lParam         = 0;    bi.iImage         = 0;    bRet = (SHBrowseForFolder(&bi) != NULL);    FreePIDL((LPITEMIDLIST)bi.pidlRoot);    return bRet;}LPITEMIDLIST MyShellFuncs::GetFolderPIDL( HWND hWnd, LPCSTR szDir ){    LPITEMIDLIST  pIDL;    LPSHELLFOLDER pSFI;    OLECHAR       szDirW[MAX_PATH];    ULONG         uEaten;    if( MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szDir, -1, szDirW, sizeof(szDirW)) == 0 )        return NULL;    if( SHGetDesktopFolder(&pSFI) == NOERROR ) {        if( pSFI->ParseDisplayName(hWnd, NULL, szDirW, &uEaten, &pIDL, NULL) == NOERROR ) {            pSFI->Release();            return pIDL;        }        pSFI->Release();    }    return NULL;}{    LPMALLOC pMalloc;    if( SHGetMalloc(&pMalloc) == NOERROR ) {        pMalloc->Free(pIDL);        pMalloc->Release();    }}  
Advertisement
oops. missed the func name of that last one.

  void MyShellFuncs::FreePIDL( LPITEMIDLIST  pIDL ){    LPMALLOC pMalloc;    if( SHGetMalloc(&pMalloc) == NOERROR ) {        pMalloc->Free(pIDL);        pMalloc->Release();    }}  
Thanx, yes I meant for windows.
I just didn''t know the BROWSEINFO struct, now that I know
that it will be a lot easier to find help about it, thanx alot

KaMiKaZe
I've done it, but now I can only have the name of the selected
folder instead of it's path, how can I get the full path of the
folder ?

[edit:] I found it, the SHGetPathFromIDList() does it.
Thanx Anonymous Poster , I wouldn't have done it without
your help.

KaMiKaZe

[edited by - Kamikaze15 on December 30, 2002 11:30:18 PM]

This topic is closed to new replies.

Advertisement