In a program based dialog,KillTimer error!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
BOOL CTestDlg::OnInitDialog()
{
	//...

	// TODO: Add extra initialization here
	SetTimer(0, 10000, NULL);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

CTestDlg::~CTestDlg()
{
	KillTimer(0); // error here, why?
}
I thought the timerID had to be non-zero value.
Even if timerID is 1, err also.
You're passing in different Window Handles to SetTimer and KillTimer, which is a nonsense.
The SetTimer function returns a value. It is this value you should pass to KillTimer function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
BOOL CTestDlg::OnInitDialog()
{
	//assume we have a member variable called m_timerID

	// TODO: Add extra initialization here
	m_timerID = SetTimer(1, 10000, NULL);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

CTestDlg::~CTestDlg()
{
	KillTimer(m_timerID); 
}


Check out the relevant info on MSDN
Topic archived. No new replies allowed.