如何使用OnTimer函数?

guzaiwang 2016-05-12 06:41:03
目前正在做一个仿真设计,就是输入起点和终点位置坐标,将其位置轨迹模拟出来,我静态模拟过程已经弄好了,但是动态模拟怎么设置呢?
我的程序具体情况是输入坐标位置,然后出现一系列位置轨迹,如。。。
现在我想将这个过程变成动态过程,因为我的初始代码是
        d=(fDX2-fDX1)/5.0;
d1=d+fDX1;
d2=d+d1;
d3=d+d2;
d4=d+d3;
w=(fDY2-fDY1)/5;
w1=w+fDY1;
w2=w+w1;
w3=w+w2;
w4=w+w3;

DrawImage(fDX1,fDY1,fDA1,1);
DrawImage(d1,w1,fDA1,1);
DrawImage(d2,w2,fDA1,1);
DrawImage(d3,w3,fDA1,1);
DrawImage(d4,w4,fDA1,1);
DrawImage(fDX2,fDY2,fDA2,1);

现在我想用ontimer函数实现,就是0.5秒刷新一次,然后运行一次DrawImage这个函数。
本人完全小白,接触mfc功能一个月,现在想请高手能不能简单的编一下ontimer函数中的代码,让我明白如何实现动态模拟过程。。。
目前我已经添加了ontimer函数
void CMyDlg::OnTimer(UINT nIDEvent) 
{
// TODO: Add your message handler code here and/or call default

CDialog::OnTimer(nIDEvent);
}

我想设置SetTimer(1,500,Null);这个是在什么位置设置呢? 还望高手指点。
...全文
587 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
rxguoblp 2016-05-15
  • 打赏
  • 举报
回复
话说,你这个图要想画的漂亮还是要费一番功夫滴,关键是你那个 DrawImage()函数,Timer到在其次。 1.在你想启动开始绘图的任意一个按钮响应函数OnBnClickedButton()里面添加:SetTimer(1,500,Null)都可以; 2.在CMyDlg::OnTimer()函数里面 DrawImage(); 3.要体现出动态过程的话,就要逐点绘制,将坐标点压入vector
fhw217 2016-05-13
  • 打赏
  • 举报
回复
在CMyDlg的OnInitDialog函数设置定时器SetTimer(...);
赵4老师 2016-05-13
  • 打赏
  • 举报
回复
LineDDA The LineDDA function determines which pixels should be highlighted for a line defined by the specified starting and ending points. BOOL LineDDA( int nXStart, // x-coordinate of line's starting point int nYStart, // y-coordinate of line's starting point int nXEnd, // x-coordinate of line's ending point int nYEnd, // y-coordinate of line's ending point LINEDDAPROC lpLineFunc, // pointer to callback function LPARAM lpData // pointer to application-defined data ); Parameters nXStart Specifies the x-coordinate of the line's starting point. nYStart Specifies the y-coordinate of the line's starting point. nXEnd Specifies the x-coordinate of the line's ending point. nYEnd Specifies the y-coordinate of the line's ending point. lpLineFunc Pointer to an application-defined callback function. For more information, see the LineDDAProc callback function. lpData Pointer to the application-defined data. Return Values If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. Windows NT: To get extended error information, callGetLastError. Remarks The LineDDA function passes the coordinates for each point along the line, except for the line's ending point, to the application-defined callback function. In addition to passing the coordinates of a point, this function passes any existing application-defined data. The coordinates passed to the callback function match pixels on a video display only if the default transformations and mapping modes are used. QuickInfo Windows NT: Requires version 3.1 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in wingdi.h. Import Library: Use gdi32.lib. See Also Lines and Curves Overview, Line and Curve Functions, LineDDAProc
lx624909677 2016-05-12
  • 打赏
  • 举报
回复
在OnTimer中对你就行改变数据的点进行数值改变,然后在OnPaint里去根据这些点来重新绘图,OnTimer就是一个定时器,每隔一个时间就会自动执行,如果你想让一个点沿着横轴每次移动一个像素,那么你只要把横轴坐标每次加一,纵轴不变,之后绘图时候去使用这个点坐标就行了
guzaiwang 2016-05-12
  • 打赏
  • 举报
回复
忘记说 我的10,10,0的意思就是足球机器人的坐标是 (10,10)角度是0度。。

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧