19,468
社区成员
发帖
与我相关
我的任务
分享
vector <UINT> m_yInfo;// .h
// TODO: Add extra initialization here
CRect rc;
GetClientRect(rc);
UINT y;
for(int jj=0 ;jj < rc.right;jj++)
{
y=rc.Height()/3 * sin(jj*PI/180);
m_yInfo.push_back(y);
}
m_Start=0;
//
int tm=60000/rc.Width();// 83 ms
SetTimer(1,tm,0);
2 定时器
void CScrollMemDCDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CRect rc;
GetClientRect(rc);
UINT y;
y=rc.Height()/3 * sin(m_yInfo.size()*PI/180);
m_yInfo.push_back(y);
//
m_Start++;
//
rc.top+=50;
rc.bottom-=80;
InvalidateRect(&rc);
// CDialog::OnTimer(nIDEvent);
}
3 绘制
CPaintDC dc(this); // device context for painting
// prepare bmp;br
CDC memDC;
memDC.CreateCompatibleDC(&dc);
CRect rc;
GetClientRect(rc);
CBitmap bmp;
bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());
memDC.SelectObject(&bmp);
CBrush br;
br.CreateSolidBrush(RGB(255,255,200));
int tm=0;
{
memDC.FillRect(&rc,&br);
// h axis
memDC.MoveTo(0,HOR_POS);
memDC.LineTo(rc.right,HOR_POS);
//
memDC.MoveTo(0,m_yInfo[m_Start]+HOR_POS);
for(UINT jj=0;jj<rc.right;jj++)
{
memDC.LineTo(jj,m_yInfo[jj+m_Start]+HOR_POS);
}
for(UINT kk=0;kk<m_yInfo.size();kk+=(int)(10000/83))
{// 83ms each ; 10000/83ms=120 pt
CString str;
str.Format("% 3d秒",tm);// 10sec
memDC.TextOut(kk-m_Start-20,HOR_POS+20,str);
memDC.MoveTo(kk-m_Start,HOR_POS-10);
memDC.LineTo(kk-m_Start,HOR_POS+10);
tm+=10;
}
//
dc.BitBlt(0,0,rc.Width(),rc.Height(),&memDC,0,0,SRCCOPY);
}