关于settimer中nidevent的使用

今天在测试一个小东东,忽然不知道settimer肿么用了,查了查msdn,仔细的看了看使用方法,发现参数很有意思:

A nonzero timer identifier. If the hWnd parameter is NULL, and the nIDEvent does not match an existing timer then it is ignored and a new timer ID is generated. If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. WhenSetTimer replaces a timer, the timer is reset. Therefore, a message will be sent after the current time-out value elapses, but the previously set time-out value is ignored. If the call is not intended to replace an existing timer,nIDEvent should be 0 if the hWnd is NULL.

这是nIDEvent的解释,亮点是: If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer

就是说,如果这个nidevent如果已经存在,那么新传入的这个就会替代之前的那个,并且重新开始计时。

这时自己犯2的做了个小测验:

首先设置两个timer,1(10s),2(20s),使用mfc中默认的消息响应函数。

开始运行,一切正常。

然后,用settimer设置了另外一个nidevent为1(10S)的timer,并且其中的回调函数更改。

windows默认函数:

void Ctest_linux_esam_listDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
// esam_delete_expired_ele_clean_list();


switch(nIDEvent)
{
case 1:
AfxMessageBox(_T("OnTimer event 1"));
break;
case 2:
AfxMessageBox(_T("OnTimer event 2"));
break;
default:
break;
}

CDialog::OnTimer(nIDEvent);

}



自己的timeproc:

VOID CALLBACK timerfunc(
 HWND hwnd,
 UINT uMsg,
 UINT_PTR idEvent,
 DWORD dwTime
)
{
switch(idEvent)
{
case 1:AfxMessageBox(_T("enter timerfunc event 1"));
break;
case 2:AfxMessageBox(_T("enter timerfunc event 2"));
break;
default:break;
}
}



这时 亮点出来了:当nidevent为1的timeout了,会弹出enter timerfunc event 1。而在第二个timeout时,会弹出OnTimer event 2·····

感觉很神奇哇,回调都改变了,居然还能准确区分。猜想是调用settimer的时候windows为每个nidevent做了回调函数的地址映射,具体的没研究,如果哪位大神知道,请告知小弟~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值