更新一下自己的代码
int i = 0,j = 0;
void CWangLiuLin190304View::OnDraw(CDC* pDC)
{
CWangLiuLin190304Doc* pDoc = GetDocument();
if(j == 10) ::TextOut((pDC->GetSafeHdc()),0,0,"\n\r",lstrlen("\n\r"));//每10个换行
if(i == 1)
{
int a;
a = rand()%25;
a += 'a';
::TextOut((pDC->GetSafeHdc()),0,0,((CString)a),lstrlen((CString)a));
}
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
两段代码
void CWangLiuLin190304View::OnBegin()
{
// TODO: Add your command handler code here
SetTimer(1,500,NULL);
i = 1;
}
void CWangLiuLin190304View::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
j++;
if(i == 1)
{
CDC *pDC=GetDC(); //调用OnDraw(pDC)重画
OnDraw(pDC);
}
if(j == 99)
{
KillTimer(1);//100个结束
}
//CView::OnTimer(nIDEvent);
}
void CWangLiuLin190304View::OnEnd()
{
// TODO: Add your command handler code here
i = 0;
KillTimer(1);
}
::TextOut(要写在OnPaint里面
否则窗体刷新就被擦除了。
你可以定义一个全局变量,在你的定时器里设置,然后让窗体的 Paint 去绘图,在定时器里再刷新客户区
####################################################
有运行结果截图,有关键代码截图,有详尽的注释。
我那么完美的答案,被论坛管理员删除了,不知道为什么。
只好再补充一下源代码链接:
链接: https://pan.baidu.com/s/1JPC8UloawjY06CE-QKQbQw
提取码: 4vb6
####################################################