我想做一个速度拼比程序,第一部要获得系统时间,然后转换成字符串显示
代码如下:
void CTestSpeedDlg::OnBtnAdo() 
{
// TODO: Add your control notification handler code here
CString str;
GetSystemTime(&LastTime);
str.Format(LastTime.wMinute);
AfxMessageBox(str);

}
执行到str.Format(LastTime.wMinute);这一步便出错
请问各位大侠怎样把WORD类型转换为CString类型,
其中SYSTEMTIME 的定义如下
typedef struct _SYSTEMTIME {
    WORD wYear;
    WORD wMonth;
    WORD wDayOfWeek;
    WORD wDay;
    WORD wHour;
    WORD wMinute;
    WORD wSecond;
    WORD wMilliseconds;
} SYSTEMTIME;

解决方案 »

  1.   

    TryTry str.Format("%d",LastTime.wMinute)
      

  2.   

    改成
    str.Format("%d",LastTime.wMinute);
      

  3.   

    试一下:str.Format("%ld",LastTime.wMinute);
      

  4.   

    谢谢,我已经通过了!
    顺便问一下
    在这一句GetSystemTime(LastTime);如果去掉&这个符号后
    会产生错误E:\A_VC\vcTest\TestSpeed\TestSpeedDlg.cpp(197) : error C2664: 'GetSystemTime' : cannot convert parameter 1 from 'struct _SYSTEMTIME' to 'struct _SYSTEMTIME *'
    请问&这个符号在这里是做什么用的,
      

  5.   

    WORD: 16-bit unsigned integer. (in MSDN)
      

  6.   

    VOID GetSystemTime(
      LPSYSTEMTIME lpSystemTime   // address of system time structure
    );                               ^^^^^^^
                                     取地址
      

  7.   

    我对LastTime的定义如下:
    SYSTEMTIME LastTime;这个LastTime 的类型跟LPSYSTEMTIME 不一致,却能通过。
    而为什么LPSYSTEMTIME LastTime;定义却不行。
    不管怎样都得不到当前时间。
      

  8.   

    与sprintf()的用法一致,就是格式化字符串!
      

  9.   

    LPSYSTEMTIME 就等于SYSTEMTIME* 
    GetSystemTime是将返回值放到lpSystemTime指向的结构中去,你传一个空指针进去怎么会有用呢?