Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to open the dialog 'Open Folder' not 'Open File' ??

How to open the dialog 'Open Folder' not 'Open File' ??

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Grrrr
    wrote on last edited by
    #1

    Thanks!

    B R J 3 Replies Last reply
    0
    • G Grrrr

      Thanks!

      B Offline
      B Offline
      BaldwinMartin
      wrote on last edited by
      #2

      Hi You want to open a folder with a return of a path? or Open a folder to make changes to it's attributes? Best Wishes and Happy Holiday's, ez_way

      1 Reply Last reply
      0
      • G Grrrr

        Thanks!

        R Offline
        R Offline
        RChin
        wrote on last edited by
        #3

        If you're talking about opening Window's folder selection dialog, take a look at the ::SHBrowseForFolder() API. You'll need to include the <Shlwapi.h> header file.


        I Dream of Absolute Zero

        G 1 Reply Last reply
        0
        • R RChin

          If you're talking about opening Window's folder selection dialog, take a look at the ::SHBrowseForFolder() API. You'll need to include the <Shlwapi.h> header file.


          I Dream of Absolute Zero

          G Offline
          G Offline
          Grrrr
          wrote on last edited by
          #4

          Yeah. I really want this function. But i found this dialog is not similar with use FileDialog(),When i use FileDialog to open a dialog to open a file.

          R 1 Reply Last reply
          0
          • G Grrrr

            Yeah. I really want this function. But i found this dialog is not similar with use FileDialog(),When i use FileDialog to open a dialog to open a file.

            R Offline
            R Offline
            RChin
            wrote on last edited by
            #5

            Grrrr wrote: But i found this dialog is not similar with use FileDialog(), Yeah, I know that using the Windows API folder function is not as easy as using MFC's CFileDialog.
            However I did recall something here on CP, so a little searching has uncovered This:[^]
            Its a C++ wrapper for the ::SHBrowseForFolder API. I havent used it myself, but I probably will try it out in my next project.


            I Dream of Absolute Zero

            1 Reply Last reply
            0
            • G Grrrr

              Thanks!

              J Offline
              J Offline
              Juan Carlos SM
              wrote on last edited by
              #6

              try this class: ------------------------------ DirDialog.h class CDirDialog { public: CDirDialog(); virtual ~CDirDialog(); BOOL DoBrowse(CWnd *pwndParent = NULL); CString m_strWindowTitle; CString m_strPath; CString m_strInitDir; CString m_strSelDir; CString m_strTitle; int m_iImageIndex; BOOL m_bStatus; private: virtual BOOL SelChanged(LPCSTR lpcsSelection, CString& csStatusText) { return TRUE; }; static int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData); }; ------------------------------ DirDialog.cpp // Callback function called by SHBrowseForFolder's browse control // after initialization and when selection changes int __stdcall CDirDialog::BrowseCtrlCallback(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) { CDirDialog* pDirDialogObj = (CDirDialog*)lpData; if (uMsg == BFFM_INITIALIZED) { if (!pDirDialogObj->m_strSelDir.IsEmpty() ) ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)(LPCTSTR)(pDirDialogObj->m_strSelDir)); if (!pDirDialogObj->m_strWindowTitle.IsEmpty() ) ::SetWindowText(hwnd, (LPCTSTR) pDirDialogObj->m_strWindowTitle); } else if (uMsg == BFFM_SELCHANGED) { LPITEMIDLIST pidl = (LPITEMIDLIST)lParam; char selection[MAX_PATH]; if (!::SHGetPathFromIDList(pidl, selection) ) selection[0] = '\0'; CString csStatusText; BOOL bOk = pDirDialogObj->SelChanged(selection, csStatusText); if (pDirDialogObj->m_bStatus ) ::SendMessage(hwnd, BFFM_SETSTATUSTEXT , 0, (LPARAM)(LPCSTR)csStatusText); ::SendMessage(hwnd, BFFM_ENABLEOK, 0, bOk); } return 0; } ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CDirDialog::CDirDialog() { m_bStatus = FALSE; } CDirDialog::~CDirDialog() { } BOOL CDirDialog::DoBrowse(CWnd *pwndParent) { if (!m_strSelDir.IsEmpty()) { m_strSelDir.TrimRight(); if( m_strSelDir.Right(1) == "\\" || m_strSelDir.Right(1) == "//" ) m_strSelDir = m_strSelDir.Left(m_strSelDir.GetLength() - 1); } LPMALLOC pMalloc; if (SHGetMalloc(&pMalloc) != NOERROR ) return FALSE; BROWSEINFO bInfo; LPITEMIDLIST pidl; ZeroMemory((PVOID)&bInfo, sizeof(BROWSEINFO) ); BOOL bIsRepository(m_strInitDir.IsEmpty() ); if (!m_strInitDir.IsEmpty() ) { OLECHAR olePath[

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups