Search
 
SCRIPT & CODE EXAMPLE
 

CPP

C++ selectin file location using Win32 API

#include <windows.h>
#include <string>
#include <shlobj.h>
#include <iostream>
#include <sstream>

static int CALLBACK BrowseCallbackProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM lpData)
{

    if(uMsg == BFFM_INITIALIZED)
    {
        std::string tmp = (const char *) lpData;
        std::cout << "path: " << tmp << std::endl;
        SendMessage(hwnd, BFFM_SETSELECTION, TRUE, lpData);
    }

    return 0;
}

std::string BrowseFolder(std::string saved_path)
{
    TCHAR path[MAX_PATH];

    const char * path_param = saved_path.c_str();

    BROWSEINFO bi = { 0 };
    bi.lpszTitle  = ("Browse for folder...");
    bi.ulFlags    = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
    bi.lpfn       = BrowseCallbackProc;
    bi.lParam     = (LPARAM) path_param;

    LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );

    if ( pidl != 0 )
    {
        //get the name of the folder and put it in path
        SHGetPathFromIDList ( pidl, path );

        //free memory used
        IMalloc * imalloc = 0;
        if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
        {
            imalloc->Free ( pidl );
            imalloc->Release ( );
        }

        return path;
    }

    return "";
}

int main(int argc, const char *argv[])
{
    std::string path = BrowseFolder(argv[1]);
    std::cout << path << std::endl;
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ str 
Cpp :: gcc compile multi thread 
Cpp :: c++ merging algorithm 
Cpp :: flutter container margin 
Cpp :: 400 watt hour per kg 
Cpp :: std remove example 
Cpp :: determining a string is subsequence of another 
Cpp :: default argument c++ 
Cpp :: fast scan in c++ 
Cpp :: [3,2,4,-1,-4] 
Cpp :: Targon lol 
Cpp :: cosnt cast 
Cpp :: c++ copy with transform 
Cpp :: program in c++ for simple interest rate 
Cpp :: how to test if char in = to another in c++ 
Cpp :: Patrick and Shopping codeforces in c++ 
Cpp :: test3 
Cpp :: c++ code 
Cpp :: set app icon qt 
Cpp :: vector of vector definaion in c++ 
Cpp :: hola mundo c++ 
Cpp :: constant qualifier c++ "error display" 
Cpp :: how can I convert each and every element of string push into set in c++? 
Cpp :: split date and time in a column in db browser 
Cpp :: how to make negative number positive in c++ 
Cpp :: min stack 
Cpp :: how to convert n space separated integers in c++ 
Cpp :: Default code in C++ for VSCode 
Cpp :: decrement c++ 
Cpp :: linux x11 copy paste event 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =