Standard browse folder Window.

Standard browse folder Window.

SHBrowseForFolder

See version :

Pas de dépendances

Download :

#include <windows.h>
#include <tchar.h>
#include <shlobj.h>
#include <stdio.h>

int CALLBACK BrowseForFolderCallback(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData)
{
    TCHAR szPath[MAX_PATH+1];
    switch(uMsg)
    {
    case BFFM_INITIALIZED:
        SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
        break;
    case BFFM_SELCHANGED: 
        if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szPath)) 
        {
            SendMessage(hwnd, BFFM_SETSTATUSTEXT,0,(LPARAM)szPath);    
        }
        break;
    }
    return 0;
}

BOOL BrowseFolders(HWND hwnd, LPTSTR lpszFolder, LPTSTR lpszTitle)
{
    BROWSEINFO bi;
    LPITEMIDLIST pidl;
    bi.hwndOwner = hwnd;
    bi.pidlRoot = NULL;
    bi.pszDisplayName = NULL;
    bi.lpszTitle = lpszTitle;
    bi.ulFlags = BIF_STATUSTEXT;
    bi.lpfn = BrowseForFolderCallback;
    bi.lParam = (LPARAM)lpszFolder;
    pidl = SHBrowseForFolder(&bi);
    if (pidl)
    {
        if (SHGetPathFromIDList(pidl,lpszFolder)) 
        {
            return TRUE;
        }
    }
    return FALSE;
}

int main()
{
    TCHAR rep[MAX_PATH+1];
    if (!BrowseFolders(NULL,rep,_T("Choix du repertoire")))
        printf("Annule\n");
    else
        _tprintf(_T("Choisi : %s\n"),rep);
    return 0;
}



Explanations

	No explanations yet.