#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;
}
Code Example |
---|
Cpp :: Convert a hexadecimal number into decimal c++ |
Cpp :: how many months have 31 days |
Cpp :: convert int to string in c++ |
Cpp :: c++ erase remove |
Cpp :: c++ operator overloading |
Cpp :: ascii cpp |
Cpp :: C++ std::optional |
Cpp :: how to use custom array in c++ |
Cpp :: quicksort geeksforgeeks |
Cpp :: std::copy C ++ |
Cpp :: print stack without pop c++ |
Cpp :: c++ pre-processor instructions |
Cpp :: convert char to int c++ |
Cpp :: c++ tuple |
Cpp :: C++ :: |
Cpp :: C++ Nested if...else |
Cpp :: string number to integer number C++ |
Cpp :: c++ recursion |
Cpp :: how to declare a vector of int in c++ |
Cpp :: how creat matrix column in c++ |
Cpp :: clear previous terminal output c++ |
Cpp :: c++ class |
Cpp :: initialize 2d vector c++ |
Cpp :: string concatenation operator overloading c++ |
Cpp :: Basic Input / Output in C++ |
Cpp :: iomanip header file in c++ |
Cpp :: swap alternate elements in an array c++ problem |
Cpp :: delete c++ |
Cpp :: c++ function pointer variable |
Cpp :: Shell-Sort C++ |