settimer函数的使用

wil 2003-04-24 05:10:25
我写了一个关于settimer函数的小程序,运行的时候没有执行settimer函数中指定的回调函数,具体出错在什么地方,请指教。
代码如下:
#include <iostream.h>
#include <windows.h> /* For the CreateThread prototype */

int count=0;

VOID CALLBACK timer(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
)
{
cout<<"hello "<<count++<<endl;
return ;
}
void main()
{
int a;
cout<<"intput a integer"<<endl;
int send=SetTimer(NULL,0,3000,(TIMERPROC)timer);
if(send)
cout<<"success"<<send<<endl;
KillTimer(NULL,send);
cin>>a;
}
...全文
63 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wil 2003-04-25
  • 打赏
  • 举报
回复
我该怎样设置使回复自动发到我的邮箱里?
wil 2003-04-25
  • 打赏
  • 举报
回复
如果我不用下面的语句
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
仍然不能触发回调函数。
在上面的程序中,除了能接收时钟消息外,还能接收别的消息吗?
使用上述语句会使程序处于无穷循环当中。比如说当我接收到网络数据后就要取消时钟,继续往下执行,我有该如何处理,我总不能总在这儿循环吧。
wil 2003-04-25
  • 打赏
  • 举报
回复
我顶
lifanxi 2003-04-24
  • 打赏
  • 举报
回复
你用法不对,刚把Timer建起来,然后就又把它Kill掉了,没机会运行呀!
下面的程序可以运行。
#include <iostream>
#include <windows.h> /* For the CreateThread prototype */
using namespace std;

int count=0;

VOID CALLBACK timer(
HWND hwnd, // handle of window for timer messages
UINT uMsg, // WM_TIMER message
UINT idEvent, // timer identifier
DWORD dwTime // current system time
)
{
cout<<"hello "<<count++<<endl;
return ;
}
void main()
{
MSG msg;
cout<<"intput a integer"<<endl;
int send=SetTimer(NULL,0,3000,(TIMERPROC)timer);
if(send)
cout<<"success"<<send<<endl;

while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}

KillTimer(NULL,send);

}

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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