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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to select a required directory

how to select a required directory

Scheduled Pinned Locked Moved C / C++ / MFC
tutorial
9 Posts 5 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.
  • K Offline
    K Offline
    keerthikaaa
    wrote on last edited by
    #1

    hai to all i would like to know how can we select a particular directory by using the CFileDialog . And display the selected directory in a static text or edit box. :)

    P R H stefanmihaimogaS K 5 Replies Last reply
    0
    • K keerthikaaa

      hai to all i would like to know how can we select a particular directory by using the CFileDialog . And display the selected directory in a static text or edit box. :)

      P Offline
      P Offline
      parichaybp
      wrote on last edited by
      #2

      BOOL CCreateDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_Enter_Location = "C:\\DS\\Index\\"; UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }

      H 1 Reply Last reply
      0
      • K keerthikaaa

        hai to all i would like to know how can we select a particular directory by using the CFileDialog . And display the selected directory in a static text or edit box. :)

        R Offline
        R Offline
        Ryan Binns
        wrote on last edited by
        #3

        Have a look at SHBrowseForFolder() instead. It's specifically designed for allowing the user to choose folders rather than files. CFileDialog designed for choosing files, not folders.

        Ryan

        "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

        1 Reply Last reply
        0
        • K keerthikaaa

          hai to all i would like to know how can we select a particular directory by using the CFileDialog . And display the selected directory in a static text or edit box. :)

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          Hi keerthikaaa, maybe it is some helpful to you CFileDialog m_dlg(1); m_dlg.DoModal(); GetDlgItem(IDC_EDIT1)->SetWindowText(m_dlg.GetPathName()); -- modified at 2:35 Tuesday 11th April, 2006 BROWSEINFO bi; TCHAR m_DisplayName[MAX_PATH]; m_DisplayName[0]='\0'; memset(&bi, 0x00, sizeof(bi)); bi.hwndOwner = this->m_hWnd; bi.pszDisplayName = m_DisplayName; bi.ulFlags = BIF_EDITBOX; LPITEMIDLIST pidl = SHBrowseForFolder(&bi); if (pidl) SHGetPathFromIDList(pidl, m_DisplayName); GetDlgItem(IDC_EDIT1)->SetWindowText(m_DisplayName);

          K 1 Reply Last reply
          0
          • P parichaybp

            BOOL CCreateDlg::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_Enter_Location = "C:\\DS\\Index\\"; UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }

            H Offline
            H Offline
            Hamid Taebi
            wrote on last edited by
            #5

            Hi parichaybp, Can you be more specific

            1 Reply Last reply
            0
            • K keerthikaaa

              hai to all i would like to know how can we select a particular directory by using the CFileDialog . And display the selected directory in a static text or edit box. :)

              stefanmihaimogaS Offline
              stefanmihaimogaS Offline
              stefanmihaimoga
              wrote on last edited by
              #6

              I recomend you to use Davide Calabro's CFileDialogST[^] - very good for folder selection!

              1 Reply Last reply
              0
              • K keerthikaaa

                hai to all i would like to know how can we select a particular directory by using the CFileDialog . And display the selected directory in a static text or edit box. :)

                K Offline
                K Offline
                keerthikaaa
                wrote on last edited by
                #7

                hai to all i have written the code like this for getting a directory selcted and display the path of the selected directory. i was able to select the directory but it is not opening the directory. And the path is not displayed in the edit box which i have specified. here it is: static char BASED_CODE szFilter[] = "Directory Files (*.dir) | *.dir ||"; //create the file open dialog CFileDialog m_ldFile(TRUE, ".dir",m_sResults,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter); //Show the file open dialog and capture result if(m_ldFile.DoModal()==IDOK) { m_sResults=m_ldFile.GetFolderPath(); //Update the Dialog UpdateData(FALSE); } so anyone of u help to get out of this. :)

                R 1 Reply Last reply
                0
                • K keerthikaaa

                  hai to all i have written the code like this for getting a directory selcted and display the path of the selected directory. i was able to select the directory but it is not opening the directory. And the path is not displayed in the edit box which i have specified. here it is: static char BASED_CODE szFilter[] = "Directory Files (*.dir) | *.dir ||"; //create the file open dialog CFileDialog m_ldFile(TRUE, ".dir",m_sResults,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter); //Show the file open dialog and capture result if(m_ldFile.DoModal()==IDOK) { m_sResults=m_ldFile.GetFolderPath(); //Update the Dialog UpdateData(FALSE); } so anyone of u help to get out of this. :)

                  R Offline
                  R Offline
                  Ryan Binns
                  wrote on last edited by
                  #8

                  keerthikaaa wrote:

                  static char BASED_CODE szFilter[] = "Directory Files (*.dir) | *.dir ||"

                  Have you got a special file type that has a ".dir" extension? File-system directories don't end in ".dir" normally. By specifying this filter, you'll only allow files that end in ".dir" to be shown in the list control.

                  Ryan

                  "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"

                  1 Reply Last reply
                  0
                  • H Hamid Taebi

                    Hi keerthikaaa, maybe it is some helpful to you CFileDialog m_dlg(1); m_dlg.DoModal(); GetDlgItem(IDC_EDIT1)->SetWindowText(m_dlg.GetPathName()); -- modified at 2:35 Tuesday 11th April, 2006 BROWSEINFO bi; TCHAR m_DisplayName[MAX_PATH]; m_DisplayName[0]='\0'; memset(&bi, 0x00, sizeof(bi)); bi.hwndOwner = this->m_hWnd; bi.pszDisplayName = m_DisplayName; bi.ulFlags = BIF_EDITBOX; LPITEMIDLIST pidl = SHBrowseForFolder(&bi); if (pidl) SHGetPathFromIDList(pidl, m_DisplayName); GetDlgItem(IDC_EDIT1)->SetWindowText(m_DisplayName);

                    K Offline
                    K Offline
                    keerthikaaa
                    wrote on last edited by
                    #9

                    hai whitesky thanks for ur help i got it :)

                    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