问题描述
你好!我的以下代码有问题,它给我CFileDialog部分一个错误:
错误C2664:``CFileDialog :: CFileDialog(BOOL,LPCTSTR,LPCTSTR,DWORD,LPCTSTR,CWnd *,DWORD,BOOL)'':无法将参数2从``const char [5]''转换为``LPCTSTR''
Hello! I have a problem with the following code, it gives me an error to CFileDialog part:
error C2664: ''CFileDialog::CFileDialog(BOOL,LPCTSTR,LPCTSTR,DWORD,LPCTSTR,CWnd *,DWORD,BOOL)'' : cannot convert parameter 2 from ''const char [5]'' to ''LPCTSTR''
void CROSH1Dlg::OnBnClickedSave()
{
UpdateData();
CStudentGrade StdGrades;
if( this->m_StudentName == "" )
return;
//strcpy (StdGrades.StudentName, this->m_StudentName);
StdGrades.StudentName = this->m_StudentName;
StdGrades.SchoolYear1 = this->m_SchoolYear1;
StdGrades.SchoolYear2 = this->m_SchoolYear2;
StdGrades.English = this->m_English;
StdGrades.History = this->m_History;
StdGrades.Economics = this->m_Economics;
StdGrades.Language2 = this->m_2ndLanguage;
StdGrades.Geography = this->m_Geography;
StdGrades.Arts = this->m_Arts;
StdGrades.Math = this->m_Math;
StdGrades.Science = this->m_Science;
StdGrades.PhysEduc = this->m_PhysEduc;
StdGrades.Total = this->m_Total;
StdGrades.Average = this->m_Average;
CString strFilename = this->m_StudentName;
CFile fleGrades;
char strFilter[] = { "Student Grades (*.dnt)|*dnt|All Files (*.*)|*.*||" };
CFileDialog dlgFile(FALSE, ".dnt", strFilename, 0, strFilter);
if( dlgFile.DoModal() == IDOK )
{
// Save the record in binary format
ofstream stmGrades(dlgFile.GetFileName(), ios::binary);
stmGrades.write((char *)&StdGrades, sizeof(StdGrades));
// Reset the dialog box in case the user wants to enter another record
m_StudentName = "";
m_SchoolYear1 = 2000;
m_SchoolYear2 = 2001;
m_English = 0.00;
m_History = 0.00;
m_Economics = 0.00;
m_2ndLanguage = 0.00;
m_Geography = 0.00;
m_Arts = 0.00;
m_Math = 0.00;
m_Science = 0.00;
m_PhysEduc = 0.00;
m_Total = 0.00;
m_Average = 0.00;
}
UpdateData(FALSE);
}
推荐答案
CFileDialog dlgFile(FALSE,_T(".dnt"), strFilename, 0, strFilter);
和使用.. TCHAR strFilter[] = _T("Student Grades (*.dnt)|*dnt|All Files (*.*)|*.*||" );
and use..TCHAR strFilter[] = _T("Student Grades (*.dnt)|*dnt|All Files (*.*)|*.*||" );
CString strDefExt = ".dnt";
CFileDialog dlgFile(FALSE, strDefExt, strFilename, 0, strFilter);
caption.Format("Student: %s", name);
错误C2664:``无效的ATL :: CStringT< basetype,stringtraits> :: Format(const wchar_t *,...)'':无法将参数1从``const char [3]''转换为``const wchar_t * ''
error C2664: ''void ATL::CStringT<basetype,stringtraits>::Format(const wchar_t *,...)'' : cannot convert parameter 1 from ''const char [3]'' to ''const wchar_t *''
this->m_StudentName.Format("%s", name);
完整代码在这里,我尝试创建一个打开按钮:
Full code here, I try to make a open button:
void CROSH1Dlg::OnBnClickedOpen()
{
UpdateData();
CStudentGrade StdGrades;
CFile fleGrades;
//TCHAR strFilter[] = _T("Student Grades (*.dnt)|*dnt|All Files (*.*)|*.*||" );
//CFileDialog dlgFile(FALSE,_T(".dnt"), strFilename, 0, strFilter);
TCHAR strFilter[] = _T("Student Grades (*.dnt)|*dnt|All Files (*.*)|*.*||");
CFileDialog dlgFile (TRUE,_T(".dnt"), NULL, 0, strFilter);
if( dlgFile.DoModal() == IDOK )
{
// Open a record in binary format
ifstream stmGrades(dlgFile.GetFileName(), ios::binary);
stmGrades.read((char *)&StdGrades, sizeof(StdGrades));
// Change the caption of the dialog box to reflect the current grade
char name[40];
//strcpy(name, StdGrades.StudentName);
StdGrades.StudentName=name;
CString caption;
caption.Format("Student: %s", name);
this->SetWindowText(caption);
// Display the record in the dialog box
this->m_StudentName.Format("%s", name);
this->m_SchoolYear1 = StdGrades.SchoolYear1;
this->m_SchoolYear2 = StdGrades.SchoolYear2;
this->m_English = StdGrades.English;
this->m_History = StdGrades.History;
this->m_Economics = StdGrades.Economics;
this->m_2ndLanguage = StdGrades.Language2;
this->m_Geography = StdGrades.Geography;
this->m_Arts = StdGrades.Arts;
this->m_Math = StdGrades.Math;
this->m_Science = StdGrades.Science;
this->m_PhysEduc = StdGrades.PhysEduc;
this->m_Total = StdGrades.Total;
this->m_Average = StdGrades.Average;
}
UpdateData(FALSE);
}
这篇关于Visual Studio 2010 CFileDialog错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!