使用如下代码测试:
void CTestDlgDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
CString str;


MessageBox("123");
str.Format("%d",KillTimer(1));
MessageBox(str);
SetTimer(1,400,NULL);
}
首先在对话框初始化时SetTimer,使用上面的代码,出现的第二个提示对话框值是0,如果把MessageBox("123");
注销掉,则对话框显示0
也就是说KillTimer(1)返回值会因为前面调用了MessageBox函数而不同。

解决方案 »

  1.   

    你这段代码明显有问题嘛,你的问题和MessageBox无关第一次点击按钮的时候,你的定时器1根本还不存在,返回FALSE,第二次点击时,定时器1已经创建,才会返回TRUE
      

  2.   

    我是先在OnInitDialog里SetTimer了,或者你可以再点第二次按钮试试,,
      

  3.   

    这个问题和MessageBox无关,而是你的代码有问题。你一次运行的时候,定时器1还没有设置,自然返回FALSE(0);第二次运行,定时器1已经存在所以返回TRUE(1)
    仔细看看MSDN关于KillTimer的返回值说明。
    BOOL KillTimer( int nIDEvent );Return ValueSpecifies the outcome of the function. The value is nonzero if the event was killed. It is 0 if the KillTimer member function could not find the specified timer event.
      

  4.   

    你的MessageBox只是显示,
    第二个是显示你kilTimer的返回值而已
      

  5.   

    你的MessageBox只是显示,
    第二个是显示你kilTimer的返回值而已
      

  6.   

    大哥,你试一下啊,这个按钮不管按多少次第二个对话框的结果都是0,我用KillTimer就是用来测试这个定时器是不是存在啊
      

  7.   

    晕,不会吧,分别用下面两段代码
    第一段:
    CString str;
    MessageBox("123");
    str.Format("%d",KillTimer(1));
    MessageBox(str);
    SetTimer(1,400,NULL);
    第二段:
    CString str;
    str.Format("%d",KillTimer(1));
    MessageBox(str);
    SetTimer(1,400,NULL);
    MessageBox(str);显示的结果会不一样,第一段显示0,第二段显示1,,我把MessageBox("123");换成显示模态对话框代码结果也是一样,,,
    不知怎么会你测试的结果跟我不一样,,,