CListCtrl的OnTimer问题
来源:互联网 发布:中国软件测试中心 编辑:程序博客网 时间:2024/04/30 03:34
在CListCtrl中的OnTimer,发现OnTimer只进去一次,而并没有在那里用KillTimer结束了该Timer。着了半天,终于找到答案。
PRB: OnTimer() Is Not Called Repeatedly for a List Control
Q200054
--------------------------------------------------------------------------------
The information in this article applies to:
The Microsoft Foundation Classes (MFC), included with:
Microsoft Visual C++, 32-bit Editions, versions 4.2, 5.0, 6.0
--------------------------------------------------------------------------------
SYMPTOMS
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.
CAUSE
The WM_TIMER handler in the list control calls the KillTimer function.
RESOLUTION
If you define the timer ID in the SetTimer call, do not call the default handler for WM_TIMER.
STATUS
This behavior is by design.
MORE INFORMATION
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).
In the sample code below, without the if clause in the CMyListCtrl::OnTimer function, the default WM_TIMER handler is always called, which destroys both the control's timer and your own timer. As a result, you should see a trace statement for each timer.
void CGensdiView::OnInitialUpdate()
{
CView::OnInitialUpdate();
m_pCtrl = new CMyListCtrl;
m_pCtrl->Create(WS_VISIBLE | WS_CHILD | WS_BORDER
| LVS_REPORT | LVS_EDITLABELS,
CRect(0, 0, 100, 150), this, 2134); m_pCtrl->InsertColumn(0, "one");
m_pCtrl->InsertItem(0, "0 0 0 0 0 0 0 0 0 0 0");
m_pCtrl->InsertItem(1, "1 1 1 1 1 1 1 1 1 1 1");
m_pCtrl->InsertItem(2, "2 2 2 2 2 2 2 2 2 2 2");
}void CGensdiView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_pCtrl->m_timerID = m_pCtrl->SetTimer(14, 500, NULL);
TRACE("timer %d is set\n", m_pCtrl->m_timerID);
}CMyListCtrl::CMyListCtrl()
{
m_timerID = -1;
}void CMyListCtrl::OnTimer(UINT nIDEvent)
{
if (nIDEvent != m_timerID)
CListCtrl::OnTimer(nIDEvent);
TRACE("OnTimer %d\n", nIDEvent);
}
Additional query words: CListview CListctrl WM_TIMER OnTimer
原来在CListCtrl中,默认的OnTimer会调用KillTimer。因此,如果是自己的timmerID,则不调用基类的 OnTimer 即可,而且ID尽量设置大一点。所以CListCtrl中的OnTimer结构应该如下:
if (nIDEvent == nMyTimerID)
{//是自己的Timer
.......
}
else
{
CListCtrl::OnTimer(nIDEvent);
}
- CListCtrl的OnTimer问题
- CListCtrl的OnTimer问题
- CListCtrl的显示问题?
- Ontimer的使用
- ontimer的输出
- clistctrl的标题头问题
- CListCtrl自动滚动的问题
- 关于CListCtrl::GetSubItemRect()的问题
- CListCtrl中排序的问题
- CListCtrl复选框的问题
- OnTimer
- MFC中OnTimer的应用
- Setimer和Ontimer的使用
- MFC中OnTimer的应用
- MFC中OnTimer的应用
- MFC中OnTimer的应用
- MFC中OnTimer的应用
- MFC中OnTimer的应用
- 第16周任务3
- Flex之旅--项呈示器ItemRenderer
- MySQL数据库备份的命令实际应用
- spring使用文件流形式下载文件
- winform中使用js
- CListCtrl的OnTimer问题
- 设计模式笔记1:策略模式(Strategy pattern)
- Android 在JNI中执行Java方法--C/C++调用Java
- SQL语言基础一
- 深入跨进程访问(AIDL服务)
- Android SDK 中Android.net.wifi简要分析
- 基于Java的全文检索引擎简介
- velocity 模板引擎
- 按分辨率不同调整对话框大小以及控件大小