刚刚开始学EVC,碰到日历控件,编译不成功,于是看MSDN,发现MSDN上面本身的例子我都运行通不过,不知道为什么........一直是format的问题,编译时出现:
E:\evc\3\4444444444444444444\4444444444444444444Dlg.cpp(77) : error C2664: 'Format' : cannot convert parameter 1 from 'unsigned short [6]' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
/////////////////////////////////////////////
//MSDN中CDateTimeCtrl::GetTime的例子
void CDatesDlg::OnButton2()
{
// Gain a pointer to the control.
CDateTimeCtrl* pCtrl = (CDateTimeCtrl*) GetDlgItem(IDC_DATETIMEPICKER1);
ASSERT(pCtrl != NULL);
// Get a CTime
CTime timeTime;
DWORD dwResult = pCtrl->GetTime(timeTime);
if (dwResult == GDT_VALID)
{
// The user checked the box and specified data.
CString str;
// Is it a time-only control or a date-only control?
if ((pCtrl->GetStyle() & DTS_TIMEFORMAT) == DTS_TIMEFORMAT)
str = timeTime.Format(_T("%X"));
else
str = timeTime.Format(_T("%x"));
AfxMessageBox(str);
}
else
{
// The user cleared the "none" box.
AfxMessageBox(_T("Time not set!"));
}
// Calling as SYSTIME is much the same, but calling COleDateTime
// tests the state of the COleDateTime object for validity to
// see if the user did or did not check the "none" box.
}
/////////////////////////
我自己改成 str.Format(_T("%d-%d-%d %d:%d:%d"),timeTime.GetYear(),timeTime.GetMinute(),timeTime.GetDay(),timeTime.GetHour(),timeTime.GetMinute(),timeTime.GetSecond());运行正常
但我就是不明白,为什么MSDN自己的例子不能通过
谢谢大虾们的指点