SHBrowseForFolder

Select the current or default folder using SHBrowseForFolder

Visual HTML/PHP Form Editor

Software for Windows PC

Learn more   Trial version available!

check Create the form on your computer

check Upload the form to your own web site

check Send form data as email or insert into MySQL

 

 

The function "SHBrowseForFolder" does not allow to specify the current (default) folder directly, so we need to send "BFFM_SETSELECTION" using the callback function. The folder is specified in the BROWSEINFO lparam.

 

Sample Sourcecode:

// callback function
INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
{
    if (uMsg==BFFM_INITIALIZED) SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
    return 0;
}

// browseforfolder function
// returns the folder or an empty string if no folder was selected
// hwnd = handle to parent window
// title = text in dialog
// folder = selected (default) folder

CString BrowseForFolder(HWND hwnd, CString title, CString folder)
{
    CString ret;

    BROWSEINFO br;
    ZeroMemory(&br, sizeof(BROWSEINFO));
    br.lpfn = BrowseCallbackProc;
    br.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
    br.hwndOwner = hwnd;
    br.lpszTitle = title;
    br.lParam = (LPARAM)folder.GetString();

    LPITEMIDLIST pidl = NULL;
    if ((pidl = SHBrowseForFolder(&br)) != NULL)
    {
        wchar_t buffer[MAX_PATH];
        if (SHGetPathFromIDList(pidl, buffer)) ret = buffer;
    }

    return ret;
}

// sample function call
CString folder = BrowseForFolder (this->m_hWnd, L"Select Folder", L"C:\\");

Disclaimer: The information, code snippets and samples on this page are provided "as is" without warranty of any kind. Further, Arclab Software OHG does not warrant, guarantee, or make any representations regarding the use, or the results of use, in terms of correctness, accuracy, reliability, currentness, or otherwise.