小弟我最近在研究这块东西,遇见了一个问题。希望大家能够帮忙解决一下!我想用一个文件guest.txt保存着客人的信息,需要指定其保存的位置。
我想把其效果做到就如使用迅雷下载电影时,另存为的时候只需要指定电影下载时,存放的目录即可。因为我的guest.txt文件名称是固定的,所以我想达到只需要指定文件夹即可。
不知道该如何实现,请大家帮忙!

解决方案 »

  1.   

    直接贴代码:
    void CDlgBackSet::OnButtonFolder() 
    {//选择路径
    // TODO: Add your control notification handler code here
    m_sFolder=BrowseForFolder(this->m_hWnd);
    SetDlgItemText(IDC_EDIT_FOLDER,m_sFolder);
    }
    CString CDlgBackSet::BrowseForFolder(HWND hWnd)
    {//选择保存备份路径函数
         TCHAR szTitle[] = _T("选择备份路径"); 
         TCHAR  szDisplayName[MAX_PATH] = _T("");
         TCHAR  szPath[MAX_PATH] = _T("");
         BROWSEINFO bi;     bi.hwndOwner = hWnd;
         bi.pidlRoot = NULL;
         bi.lpszTitle = szTitle;
         bi.pszDisplayName = szDisplayName;
         bi.ulFlags = BIF_RETURNONLYFSDIRS;
         bi.lpfn  = NULL;
         bi.lParam = 0;     LPITEMIDLIST pItemIDList = SHBrowseForFolder( &bi );
         if( pItemIDList )
         {
                  SHGetPathFromIDList(pItemIDList,szPath) ;
                  
                  IMalloc *pMalloc;
                  if( SHGetMalloc( &pMalloc ) != NOERROR )
                  {
                           TRACE( "Failed to get pointer to shells task allocator" ) ;
                           return szPath;
                  }
                  pMalloc->Free( pItemIDList );
                  if( pMalloc )
                       pMalloc->Release();
           }
           return szPath;
    }
      

  2.   


    void CTest::SelectDirDlg(char Dir[])
    {
    BROWSEINFO bi; 
    ITEMIDLIST *pidl; bi.hwndOwner = NULL; 
    bi.pidlRoot = NULL; 
    bi.pszDisplayName = Dir; 
    bi.lpszTitle = "选择一个目录"; 
    bi.ulFlags = BIF_RETURNONLYFSDIRS; 
    bi.lpfn = NULL; 
    bi.lParam = 0; 
    bi.iImage = 0; 
       
    pidl = SHBrowseForFolder( &bi );             /* Display "Select Folder" dialog box, Get the  folder name and convert it into a ITEMLIST data structure. */
     
       
    if ( pidl == NULL ) 
    Dir[0] = 0; 
       
    if (!SHGetPathFromIDList( pidl, Dir ))       /* Retrieve folder name from ITEMLIST structure. */ 
    Dir[0] = 0;
    }
      

  3.   

            BROWSEINFO  bi;
    bi.hwndOwner=m_hWnd;
    bi.pidlRoot=NULL;
    bi.pszDisplayName=NULL;
    bi.lpszTitle=NULL;
    bi.ulFlags=BIF_STATUSTEXT|BIF_USENEWUI|BIF_RETURNONLYFSDIRS;;
    bi.lpfn =NULL;
    bi.iImage =0;
    LPCITEMIDLIST pidl=SHBrowseForFolder(&bi);
    if(!pidl)
    return;
    TCHAR  szDisplayName[255];
    SHGetPathFromIDList(pidl,szDisplayName);
    CString str(szDisplayName);保存时要根据szDisplayName来保存路径
      

  4.   

    CFileDialog这个类看看就会了啊
      

  5.   

    CFileDialog是不行的。我有个封装类,叫做CDirDialog,需要的话留个信。当然,用各位贴出的代码也行。
      

  6.   


    好,可以给我看看,学习前辈的技巧!
    邮箱:[email protected]再次感谢大家!
      

  7.   

    我需要的是一个目录选择对话框,CFileDialog提供的是文件选择(打开/保存)对话框~多谢~