Reputation: 22285
I'm not sure if I'm doing something undocumented. I created my own class derived from CListCtrl and then overrode the OnTimer handler in it:
void CListCtrl2::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
switch(nIDEvent)
{
case MY_TIMER_ID:
{
//Do my processing
doMyProcessing();
}
break;
default:
{
//Default
CListCtrl::OnTimer(nIDEvent);
}
break;
}
}
But what seems strange to me is that this OnTimer() routine is called with timer IDs that are not mine. For instance, just from a quick debugger checkpoint research it turns out that my default
handler is called with nIDEvent
set to 45
and 43
.
Are there some timer IDs that are reserved that I should avoid using myself?
Upvotes: 2
Views: 847
Reputation: 613372
From the CListCtrl
documentation we see this text:
Also see:
- Knowledge Base article Q200054: PRB: OnTimer() Is Not Called Repeatedly for a List Control
And from that article, some pertinent excerpts:
If you call the SetTimer function to send periodic WM_TIMER messages to a list control, you may find that the WM_TIMER message handler (the OnTimer function) for a list control is called only twice.
....
The list control uses the timer for editing labels, and for scrolling. When you handle the timer message, if the timer ID is your own timer, don't call the default handler (CListCtrl::OnTimer).
So, this confirms what you observe. The list control uses the timer. I can find no documentation for the specific IDs that are used. I guess that Microsoft would not wish to commit to documenting the specific IDs that were used. They would regard the control's implementation as private and would wish to retain the option of using more timer IDs in future versions. But as IInspectable points out, they could have done that by reserving a range of IDs.
My recommendation is to regard the list control's timer as out of bounds, and reserved for use by the control. For your derived class, use a different timer. Create a message only window and use it to receive timer events. You can subclass CWnd
to achieve this.
Upvotes: 2