{"id":17,"date":"2013-07-14T15:28:42","date_gmt":"2013-07-14T15:28:42","guid":{"rendered":"https:\/\/praveenkatiyar.wordpress.com\/?p=17"},"modified":"2013-07-14T15:28:42","modified_gmt":"2013-07-14T15:28:42","slug":"browsing-folders-vc-6-0","status":"publish","type":"post","link":"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/07\/14\/browsing-folders-vc-6-0\/","title":{"rendered":"Browsing Folders (VC++ 6.0)"},"content":{"rendered":"<p><font color=\"#c0504d\" size=\"3\">while working with MFC there are dialog boxes for opening files, but no dialog box to browse&#160; a folder, the function below just does the same. code snippet below shows how one can open a folder browsing dialog box.<\/font><\/p>\n<p><font face=\"Consolas\"><font face=\"Consolas\"><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">BOOL BrowseFolder (<\/font><\/font>      <\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">H<\/font><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">WND hWnd,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color=\"#c0504d\"><strong> \/\/ Handle to the calling window.<\/strong><\/font><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">LPSTR pszDisplayName,&#160;&#160;&#160;&#160;&#160; <font color=\"#c0504d\"><strong>\/\/ Title of the dialog box<\/strong><\/font><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">BOOL bEdit,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <font color=\"#c0504d\"><strong>\/\/ whether edit box is allowed<\/strong><\/font><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">LPSTR szPath )&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <strong>&#160;<font color=\"#c0504d\">\/\/ starting path&#160; <\/font><\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">{<\/font><\/p>\n<p>         <\/font><font color=\"#c0504d\" size=\"2\" face=\"Courier New\"><strong>\/\/ TODO: Add your control notification handler code here<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">LPMALLOC pMalloc;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">BOOL bResult = FALSE ;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">\/* Gets the Shell&#8217;s default allocator *\/<\/font><\/p>\n<p><font face=\"Courier New\"><font size=\"2\"><font color=\"#0000ff\">if<\/font><font color=\"#0000ff\"> (::SHGetMalloc(&amp;pMalloc) == NOERROR)<\/font><\/font><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">{<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">BROWSEINFO bi;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">LPITEMIDLIST pidl ;<\/font><\/p>\n<p><font color=\"#c0504d\" size=\"2\" face=\"Courier New\"><strong>\/\/Get help on BROWSEINFO struct &#8211; it&#8217;s got all the bit settings.<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">bi.hwndOwner = hWnd ;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">bi.pidlRoot = NULL ;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">bi.pszDisplayName = szPath ;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">bi.lpszTitle = pszDisplayName ;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">\/\/bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS |BIF_EDITBOX ;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">bi.ulFlags = BIF_RETURNONLYFSDIRS |BIF_VALIDATE ;<\/font><\/p>\n<p><font face=\"Courier New\"><font color=\"#c0504d\" size=\"2\"><strong>\/\/ whether you want to display an edit box<\/strong><\/font><\/font><\/p>\n<p><font face=\"Courier New\"><font size=\"2\"><font color=\"#0000ff\">if<\/font><font color=\"#0000ff\"> ( bEdit ) bi.ulFlags = bi.ulFlags | BIF_EDITBOX ;<\/font><\/font><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">bi.lpfn = NULL;&#160;&#160; <strong><font color=\"#c0504d\">\/\/ No call back function<\/font><\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">bi.lParam = 0;&#160;&#160;&#160; <font color=\"#c0504d\"><strong>\/\/ No Extra parameter<\/strong><\/font><\/font><\/p>\n<p><font color=\"#c0504d\" size=\"2\" face=\"Courier New\"><strong>\/\/ This next call issues the dialog box.<\/strong><\/font><\/p>\n<p><font face=\"Courier New\"><font size=\"2\"><font color=\"#0000ff\">if<\/font><font color=\"#0000ff\"> ((pidl = ::SHBrowseForFolder(&amp;bi)) != NULL)<\/font><\/font><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">{<\/font><\/p>\n<p><font face=\"Courier New\"><font size=\"2\"><font color=\"#0000ff\">if<\/font><font color=\"#0000ff\"> (::SHGetPathFromIDList(pidl, szPath))<\/font><\/font><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">{ <\/font><\/p>\n<p><font color=\"#c0504d\" size=\"2\" face=\"Courier New\"><strong>\/\/ At this point pszBuffer contains the selected path&#160; <\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">bResult = TRUE ;<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">}<\/font><\/p>\n<p><font color=\"#c0504d\" size=\"2\" face=\"Courier New\"><strong>\/\/ Free the PIDL allocated by SHBrowseForFolder.<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">pMalloc-&gt;Free(pidl);<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">}<\/font><\/p>\n<p><font color=\"#c0504d\" size=\"2\" face=\"Courier New\"><strong>\/\/ Release the shell&#8217;s allocator.<\/strong><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">pMalloc-&gt;Release();<\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">}<\/font><\/p>\n<p><font face=\"Courier New\"><font size=\"2\"><font color=\"#0000ff\">return<\/font><font color=\"#0000ff\"> bResult ;<\/font><\/font><\/font><\/p>\n<p><font color=\"#0000ff\" size=\"2\" face=\"Courier New\">}<\/font><\/p>\n<h3>Calling the function.<\/h3>\n<p><font color=\"#0000ff\" face=\"Courier New\">TCHAR szPath [255] ;     <br \/>_tcscpy ( szPath, &quot;C:\\\\&quot; ) ;      <br \/>BOOL bSuccess = <\/font><font color=\"#0000ff\" face=\"Courier New\">BrowseFolder (<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\">this-&gt;m_hWnd, <\/font><font color=\"#0000ff\" face=\"Courier New\">&quot;Broswe Source Folder&quot;, <\/font><font color=\"#0000ff\" face=\"Courier New\">FALSE, <\/font><font color=\"#0000ff\" face=\"Courier New\">szPath ) ;     <br \/>if ( bSuccess )      <br \/><\/font><font color=\"#0000ff\" face=\"Courier New\">{<\/font><\/p>\n<p><font color=\"#0000ff\" face=\"Courier New\"><font color=\"#c0504d\"><strong>&#160; \/\/ szPath contains the selected folder.<\/strong>        <br \/><\/font>}<\/font><\/p>\n<p> <font face=\"Consolas\"><font face=\"Consolas\"><\/font><\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>while working with MFC there are dialog boxes for opening files, but no dialog box to browse&#160; a folder, the function below just does the same. code snippet below shows how one can open a folder browsing dialog box. BOOL BrowseFolder ( HWND hWnd,&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; \/\/ Handle to the calling window. LPSTR pszDisplayName,&#160;&#160;&#160;&#160;&#160; \/\/ Title of&hellip; <a class=\"more-link\" href=\"https:\/\/praveenkatiyar.in\/blog\/index.php\/2013\/07\/14\/browsing-folders-vc-6-0\/\">Continue reading <span class=\"screen-reader-text\">Browsing Folders (VC++ 6.0)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,15],"tags":[],"class_list":["post-17","post","type-post","status-publish","format-standard","hentry","category-codeproject","category-win32","entry"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/17","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=17"}],"version-history":[{"count":0,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/17\/revisions"}],"wp:attachment":[{"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=17"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=17"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/praveenkatiyar.in\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=17"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}