QA: How to disable "red dots" in a list view or tree view?
By Alexander Shargin, April 16, 2003.
Print version
Question
I'm using a list view or a tree view in my app. When the user tap-and-holds
stylus on the control the red dot animation is shown. I don't need a
context menu in my application so I want to disable these red dots.
How can I do this?
Answer
Red dots animation is displayed by SHRecognizeGesture function which is
used to recognize tap-and-hold gesture on Pocket PC. List view and tree
view controls call this function from their WM_LBUTTONDOWN handler.
But before they do they ask parent window if this action should be
performed at all. This request is made in the form of NM_RECOGNIZEGESTURE
notification. If parent window handles this notification and returns TRUE,
the red dots animation is cancelled.
In MFC things are a little more complicated. CWnd class has its own
WM_LBUTTONDOWN handler which looks like this:
void CWnd::OnLButtonDown (UINT nState, CPoint point)
{
if (!SHRecognizeGesture(point))
Default();
}
As we can see it calls SHRecognizeGesture as well. CListCtrl and
CTreeCtrl classes derive this handler from CWnd. So if you are
using one of these classes in your app, SHRecognizeGesture is
actually called twice - by MFC and by control's window proc! The
second call is disabled by handling M_RECOGNIZEGESTURE as described
above. With MFC you can handle it in the control itself, not in the
parent window, using message reflection mechanism. As to the first
call you can skip it by handling WM_LBUTTONDOWN in the control's
class and calling Default() from your handler.
Here is the code for CListCtrlNoDots class which disables both calls
to SHRecognizeGesture:
ListCtrlNoDots.h
// ListCtrlNoDots.h : header file
//
#if !defined(AFX_LISTCTRLNODOTS_H__E913DF61_511B_4BF4_82EC_04EC65DFB6AE__INCLUDE
D_)
#define AFX_LISTCTRLNODOTS_H__E913DF61_511B_4BF4_82EC_04EC65DFB6AE__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
////////////////////////////////////////////////////////////////////////////
/
// CListCtrlNoDots window
class CListCtrlNoDots : public CListCtrl
{
// Construction
public:
CListCtrlNoDots();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CListCtrlNoDots)
//}}AFX_VIRTUAL
// Implementation
public:
CPoint m_pt;
virtual ~CListCtrlNoDots();
// Generated message map functions
protected:
//{{AFX_MSG(CListCtrlNoDots)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRecognizeGesture(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
////////////////////////////////////////////////////////////////////////////
/
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations
//immediately before the previous line.
#endif
ListCtrlNoDots.cpp
// ListCtrlNoDots.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "ListCtrlNoDots.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////////////////
/
// CListCtrlNoDots
CListCtrlNoDots::CListCtrlNoDots()
{
}
CListCtrlNoDots::~CListCtrlNoDots()
{
}
BEGIN_MESSAGE_MAP(CListCtrlNoDots, CListCtrl)
//{{AFX_MSG_MAP(CListCtrlNoDots)
ON_WM_LBUTTONDOWN()
ON_NOTIFY_REFLECT(NM_RECOGNIZEGESTURE, OnRecognizeGesture)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////////////////////////////////////////////////////////
/
// CListCtrlNoDots message handlers
void CListCtrlNoDots::OnLButtonDown(UINT nFlags, CPoint point)
{
Default();
}
void CListCtrlNoDots::OnRecognizeGesture(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = TRUE;
}
You can write a similar class for tree view (CTreeCtrlNoDots,
for example) by adding the same OnLButtonDown and
OnRecognizeGesture handlers to a CTreeCtrl-derived class.
Discuss
Discuss this article.
Here you can write your comments and read comments of other developers.
|