初学vc++,我在程序里定义:CFileDialog myDialog;
却怎么也编译不过,出错信息为:
error C2512: 'CFileDialog' :no appropriate default constructor available Error executing cl.exe.
是什么原因,快快救命啊。

解决方案 »

  1.   

    CFileDialog没有无参数的缺省构造函数。
    如果是打开对话框,那么用CFileDialog myDialog(true);
    如果为保存对话框,用CFileDialog myDialog(false);
    详细参数请见MSDN。
    CFileDialog::CFileDialog
    CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter = NULL, CWnd* pParentWnd = NULL );ParametersbOpenFileDialogSet to TRUE to construct a File Open dialog box or FALSE to construct a File Save As dialog box.lpszDefExtThe default filename extension. If the user does not include an extension in the Filename edit box, the extension specified by lpszDefExt is automatically appended to the filename. If this parameter is NULL, no file extension is appended.lpszFileNameThe initial filename that appears in the filename edit box. If NULL, no filename initially appears.dwFlagsA combination of one or more flags that allow you to customize the dialog box. For a description of these flags, see theOPENFILENAME structure in the Win32 SDK documentation. If you modify the m_ofn.Flags structure member, use a bitwise-OR operator in your changes to keep the default behavior intact.lpszFilterA series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files will appear in the Files list box. See the Res section for more information on how to work with file filters.pParentWndA pointer to the file dialog-box object’s parent or owner window.