如何使CFileDialog 在DoModal() 时显示指定的目录,而不是默认目录

解决方案 »

  1.   

    CFileDialog dlg(TRUE, TEXT("TXT"), NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, TEXT("文本文件(*.txt)|*.txt|所有文件(*.*)|*.*||"), this);
    dlg.m_ofn.lpstrInitialDir="C:\\XXX\\";
    dlg.DoMal();
      

  2.   

    CFileDialog fd;
    fd.m_ofn.lpstrInitialDir=
      

  3.   

    楼上说的对。
    m_ofn is a structure of type OPENFILENAME. Use this structure to initialize the appearance of a File Open or File Save As dialog box after it is constructed but before it is displayed with the DoModal member function. 
      

  4.   

    typedef struct tagOFN { 
      DWORD         lStructSize; 
      HWND          hwndOwner; 
      HINSTANCE     hInstance; 
      LPCTSTR       lpstrFilter; 
      LPTSTR        lpstrCustomFilter; 
      DWORD         nMaxCustFilter; 
      DWORD         nFilterIndex; 
      LPTSTR        lpstrFile; 
      DWORD         nMaxFile; 
      LPTSTR        lpstrFileTitle; 
      DWORD         nMaxFileTitle; 
      LPCTSTR       lpstrInitialDir; 
      LPCTSTR       lpstrTitle; 
      DWORD         Flags; 
      WORD          nFileOffset; 
      WORD          nFileExtension; 
      LPCTSTR       lpstrDefExt; 
      LPARAM        lCustData; 
      LPOFNHOOKPROC lpfnHook; 
      LPCTSTR       lpTemplateName; 
    #if (_WIN32_WINNT >= 0x0500)
      void *        pvReserved;
      DWORD         dwReserved;
      DWORD         FlagsEx;
    #endif // (_WIN32_WINNT >= 0x0500)
    } OPENFILENAME, *LPOPENFILENAME;