我使用了两个timeSetEvent函数,同时循环执行两件事情。使用回调函数进行触发循环执行。
结果:两个timeSetEvent函数的返回值均不为零(下文程序中的ID1=16,ID2=33),说明定时器已经创建成功了,但是2个回调函数只有第一个回调函数执行(先创建的那个定时器的回调函数能执行,后创建的定时器的回调函数不能运行)。即下文中的TimeCallBack1函数能执行,TimeCallBack2函数中的代码却不执行。如果把其中一个定时器注释掉,另外一个程序运行时正常的。一直找不到原因,急啊。各位高手能否帮我分析分析,谢谢!程序很大,下面是程序的框架:
//a.cpp
ID1 = timeSetEvent(1,1,(LPTIMECALLBACK)TimeCallBack1, (DWORD)this,TIME_PERIODIC);
void PASCAL TimeCallBack1(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
//
}
//b.cpp
ID2 = timeSetEvent(10,1,(LPTIMECALLBACK)TimeCallBack2, (DWORD)this,TIME_PERIODIC);
void PASCAL TimeCallBack2(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
//
}
结果:两个timeSetEvent函数的返回值均不为零(下文程序中的ID1=16,ID2=33),说明定时器已经创建成功了,但是2个回调函数只有第一个回调函数执行(先创建的那个定时器的回调函数能执行,后创建的定时器的回调函数不能运行)。即下文中的TimeCallBack1函数能执行,TimeCallBack2函数中的代码却不执行。如果把其中一个定时器注释掉,另外一个程序运行时正常的。一直找不到原因,急啊。各位高手能否帮我分析分析,谢谢!程序很大,下面是程序的框架:
//a.cpp
ID1 = timeSetEvent(1,1,(LPTIMECALLBACK)TimeCallBack1, (DWORD)this,TIME_PERIODIC);
void PASCAL TimeCallBack1(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
//
}
//b.cpp
ID2 = timeSetEvent(10,1,(LPTIMECALLBACK)TimeCallBack2, (DWORD)this,TIME_PERIODIC);
void PASCAL TimeCallBack2(UINT uTimerID, UINT uMsg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
//
}
解决方案 »
- fatal error C1083:cannot open source file:"..." no such file or directory
- ADO执行insert into语句后没更新数据源!急急急!
- 列表控件(CListCtrl)为何不能调整列宽了呢???
- 怎样使得点住菜单栏后可以拖动窗口
- 在VC中,怎样设置MSFlexDataGrid的其中一列为隐藏
- 容器里如何交换两个元素?谢谢。
- 关于SystemParametersInfo
- 郁闷:哪些情况要UpdateData(TRUE)?它的具体意思是什么?
- 对话框设计问题,简单
- 有没有人知道dos底层开发的网站,尽管dos基本上已不存在
- 小波变换融合
- 关于两张图片对比算法
建议你:timeSetEvent函数已经过时,它是原来微软提供的一个多媒体组件库,Microsoft 建议你用CreateTimerQueueTimer。
UINT uDelay,
UINT uResolution,
LPTIMECALLBACK lpTimeProc,
DWORD_PTR dwUser,
UINT fuEvent
);
ParametersuDelay:Event delay, in milliseconds. If this value is not in the range of the minimum and maximum event delays supported by the timer, the function returns an error.uResolution:Resolution of the timer event, in milliseconds. The resolution increases with smaller values; a resolution of 0 indicates periodic events should occur with the greatest possible accuracy. To reduce system overhead, however, you should use the maximum value appropriate for your application.判断一下调用timeSetEvent的返回值吧,看看是否成功。
UINT uDelay,
UINT uResolution,
LPTIMECALLBACK lpTimeProc,
DWORD_PTR dwUser,
UINT fuEvent
);
fuEvent
Timer event type. This parameter may include one of the following values. Value Meaning
TIME_ONESHOT Event occurs once, after uDelay milliseconds.
TIME_PERIODIC Event occurs every uDelay milliseconds. TIME_PERIODIC周期到了会不会把计数器清了,
第二个函数根本没有触发条件