I've read the documentation link and several threads explaining how to make a timer. Now after hours I still can't get my test to work.

In the testDlg.h header I declare:

UINT_PTR m_uTimerId;
	CString textControl1;  // Controls an Edit Control
	afx_msg void OnBnClickedButton1();
	afx_msg void OnTimer(UINT_PTR nIDEvent);
	int myX;

myX is initialized to 0 in the dialog constructor. The button clicked function looks like this:

void CtestDlg::OnBnClickedButton1()
	textControl1 = _T("New text");
	m_uTimerId = SetTimer(1,3000,NULL);

And here is OnTimer:

void CtestDlg::OnTimer(UINT_PTR nIDEvent)
	if(myX % 2 == 0)
		textControl1 = _T("timer is");
		textControl1 = _T("working");

When I click the associated button, text in edit control updates to "New text", but the timer function is not working, because the text does not change after time elapses.

Any help would be GREATLY appreciated. I promise you!

It looks like it ought to work as such. However, you could check that;

  • You have the ON_WM_TIMER() macro in the dialog class' message map.
  • SetTimer() succeeds (returns a nonzero value).
  • UpdateData() succeeds (returns a nonzero value).
Thank you so much! The bullet points made your answer even clearer!

Thank you! There was no ON_WM_TIMER() macro. I added that single line to the message map and the problem was fixed immediately. Now I need to go back and read the msdn documentation to see how I missed that. I can't wait for the day I can read the documentation and quickly figure out how to use a function!

This question has already been answered. Start a new discussion instead.