mfc OnTimer怎么用?? 每隔一段时间执行下面的程序,达到画线的一个渐变效果》???
voidCMy123Dlg::OnStart1(){CStatic*Static_time1=(CStatic*)GetDlgItem(IDC_STATIC1);CRec...
void CMy123Dlg::OnStart1()
{
CStatic *Static_time1=(CStatic*)GetDlgItem(IDC_STATIC1);
CRect rect;
Static_time1->GetClientRect(&rect);
CDC *pDC=Static_time1->GetDC();
CPen pen1;
pen1.CreatePen(PS_SOLID,2,RGB(255,0,0));
char *pszFileName="myfile.txt";
CStdioFile myFile;
CFileException fileException;
if(myFile.Open(pszFileName,CFile::typeText|CFile::modeRead),&fileException)
{
myFile.SeekToBegin();
int N;
N=M1+M2;
CString str;
myFile.ReadString(str);
CStringArray ary;
_SplitStr(str,",",ary);
int x0,y0;
x0=atoi(ary[0]);
y0=atoi(ary[1]);
for(N;N>0;N--)
{
CString str1;
myFile.ReadString(str1);
CStringArray ary1;
_SplitStr(str1,",",ary1);
int x1,y1;
x1=atoi(ary1[0]);
y1=atoi(ary1[1]);
pDC->SelectObject(&pen1);
line(pDC,x0+5,220-y0,x1+5,220-y1);
x0=x1;
y0=y1;
}
}
else
{
TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause);
}
myFile.Close();
Static_time1->ReleaseDC(pDC);
} 展开
{
CStatic *Static_time1=(CStatic*)GetDlgItem(IDC_STATIC1);
CRect rect;
Static_time1->GetClientRect(&rect);
CDC *pDC=Static_time1->GetDC();
CPen pen1;
pen1.CreatePen(PS_SOLID,2,RGB(255,0,0));
char *pszFileName="myfile.txt";
CStdioFile myFile;
CFileException fileException;
if(myFile.Open(pszFileName,CFile::typeText|CFile::modeRead),&fileException)
{
myFile.SeekToBegin();
int N;
N=M1+M2;
CString str;
myFile.ReadString(str);
CStringArray ary;
_SplitStr(str,",",ary);
int x0,y0;
x0=atoi(ary[0]);
y0=atoi(ary[1]);
for(N;N>0;N--)
{
CString str1;
myFile.ReadString(str1);
CStringArray ary1;
_SplitStr(str1,",",ary1);
int x1,y1;
x1=atoi(ary1[0]);
y1=atoi(ary1[1]);
pDC->SelectObject(&pen1);
line(pDC,x0+5,220-y0,x1+5,220-y1);
x0=x1;
y0=y1;
}
}
else
{
TRACE("Can't open file %s,error=%u\n",pszFileName,fileException.m_cause);
}
myFile.Close();
Static_time1->ReleaseDC(pDC);
} 展开
1个回答
展开全部
classwizard中,重祥丛握载WM_TIMER消息,获得OnTimer函数(注意是针对对话框谨庆)
OnTimer函数中,调用单步函数(你这里是OnStart1?)
在对话框郑隐初始函数OnInitDialog,或者“开始绘图”按钮响应函数,调用SetTimer(1,1000,NULL);
更多追问追答
追问
我就这么做的,但是我程序中的for循环是不是要去掉?
追答
是的,你需要一个全局(或者类成员)变量来控制次数,而不是一个局部变量N,在SetTimer之前,给N赋值次数;在OnStart1最后判断,如果N到达次数,那么KillTimer停止定时器。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询