C, C++, To select folder only and get path using SHBrowseForFolder function, example source code

//Get only folder name
 ITEMIDLIST *pidlBrowse;
 WCHAR pszPathname[MAX_PATH];
 
 BROWSEINFO BrInfo;
 BrInfo.hwndOwner = GetSafeHwnd();
 BrInfo.pidlRoot = NULL;
 
 CString str =_T("c:\\"); //initial path
 LPCTSTR lpszDefaultFolder = str;
 memset(&BrInfo, 0, sizeof(BrInfo));
 BrInfo.pszDisplayName=(LPSTR)pszPathname;
 BrInfo.lpszTitle=_T("Select directory");
 BrInfo.ulFlags=BIF_RETURNONLYFSDIRS; //select folder only
 //BrInfo.ulFlags=BIF_BROWSEINCLUDEFILES; //select folder and file
 BrInfo.lParam=(LPARAM)lpszDefaultFolder;
 //BrInfo.lpfn=BrowseCallback;
 
 pidlBrowse = ::SHBrowseForFolder(&BrInfo);

 
 if (pidlBrowse != NULL)
 {
  //Get Path
  SHGetPathFromIDList(pidlBrowse, (LPSTR)pszPathname);
  AfxMessageBox((LPCSTR)pszPathname);
 }


...



Comments

Popular posts from this blog

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

OpenCV Stitching example (Stitcher class, Panorama)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

Optical Flow sample source code using OpenCV

OpenCV Drawing Example, (line, circle, rectangle, ellipse, polyline, fillConvexPoly, putText, drawContours)

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

SICK LMS511 sensor data acquisition interface (source code, C++/MFC)

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Image warping (using opencv findHomography, warpPerspective)