void CMyactivexCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{int hour,minits,scends;
CTime timer=CTime::GetCurrentTime();
CString str;
hour=timer.GetHour();
minits=timer.GetMinute();
scends=timer.GetSecond();
str.Format("%H:%M:%S",hour,minits,scends); 1.
pdc->DrawText(str,CRect(0,0,100,100),DT_CENTER); }
上面这段代码是一个自定控件里的ondraw里的代码 程序编译不会出错,但在容器如VB中一添加该控件在FORM里就弹出非法操作。程序走到1处就出错了。因为这时一段在WINCE 中的代码,timer对象不支持format函数,所以就单独把时间取出来的.
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{int hour,minits,scends;
CTime timer=CTime::GetCurrentTime();
CString str;
hour=timer.GetHour();
minits=timer.GetMinute();
scends=timer.GetSecond();
str.Format("%H:%M:%S",hour,minits,scends); 1.
pdc->DrawText(str,CRect(0,0,100,100),DT_CENTER); }
上面这段代码是一个自定控件里的ondraw里的代码 程序编译不会出错,但在容器如VB中一添加该控件在FORM里就弹出非法操作。程序走到1处就出错了。因为这时一段在WINCE 中的代码,timer对象不支持format函数,所以就单独把时间取出来的.
CTime t( 1999, 3, 19, 22, 15, 0 );
// 10:15 PM March 19, 1999
CString s = t.Format( "%A, %B %d, %Y" );
这句有问题:str.Format("%H:%M:%S",hour,minits,scends);
你是将其格式化为CString的,所以不能这样用,要这样才行:
str.Format("%d:%d:%d",hour,minits,scends);
如要保证显示的位数不变,则可这样:
str.Format("%02d:%02d:%02d",hour,minits,scends);