Trouble with tap and hold

Trouble with tap and hold

Post by MarkMurp » Mon, 06 Jan 2003 10:35:45


I'm using the messageCE dll from IntelProg to capture messages in evb
in order to simulate tap and hold context menu popups.  I'm
subclassing a listview control just as the example on Microsoft's site

I got around a few of the bugs in the example, but the last problem
has me stumped.  It is not possible it seems to accurately detect a
tap as opposed to a tap and hold.

When a WM_LBUTTONDOWN is captured, this starts the detection process.
If 1 second timer expires before we detect the stylus lifting then the
context menu appears.

Unfortunately, Microsoft decided to dispense with the WM_LBUTTONUP
message (in most cases).  It arrives infrequently and unpredictably.
The IntelProg author apparently noticed this and made clever use of
the WM_CAPTURECHANGED message.  If this message is received 3 times
before the timer expires, the user must have lifted the stylus.
Unfortunately, lifting the stylus may only result in only 2 of these
messages.  In this case (which is frequent, but unpredictable), the
timer will expire and a context menu will appear, when the user meant
just a tap.

The code for handling the messages is below.  Has anyone gotten a tap
and hold kludge to reliably work in VBE?  Any pointers would be


'Handle captured messages of messageCE subclassed listview control.
Public Sub WinProc(hwnd As Long, message As Long, wParam As Long,
lParam As Long)

    Dim x As Single
    Dim y As Single

    Select Case message

            ' Get coordinates
            y = Int(lParam / 65536)
            x = lParam - y * 65536

            ' Save menu position
            iMenuLeft = x * 15 + Screen.ActiveControl.Left
            iMenuTop = y * 15 + Screen.ActiveControl.Top

            tmrMenu.Enabled = True
            piCaptureCount = 0 ' Reset WM_CAPTURECHANGED message

        Case WM_LBUTTONUP  'Is never received!
            tmrMenu.Enabled = False
            piCaptureCount = 0

            piCaptureCount = piCaptureCount + 1

            ' If 3 after WM_LBUTTONDOWN, stop timer (=stylus released)
            If piCaptureCount > 2 Then
                 'user intended a tap
                 tmrMenu.Enabled = False
                 piCaptureCount = 0
            End If
    End Select

End Sub


1. tap-and-hold w/ppc2002 and mfc

i can't seem to get the tap-and-hold feature to work on my single dialog mfc
app with two edit controls and a button on it.  the "animation" only works
when i tap-and-hold the window area outside the edit controls.  in the edit
controls, if text is selected and then tap-and-hold started over selected
text the text becomes unselected and the caret moves to where the
tap-and-hold was started.

TestAppMFCDlg.h (1)
(OnContextMenu INSIDE generated map functions)
 HICON m_hIcon;

 // Generated message map functions  {{AFX_MSG(CTestAppMFCDlg)
 virtual BOOL OnInitDialog();
    afx_msg void OnButtonGetCode();
    afx_msg void OnContextMenu(CWnd *pWnd,CPoint point);

TestAppMFCDlg.h (2)
(OnContextMenu OUTSIDE generated map functions)
 HICON m_hIcon;

 // Generated message map functions
 virtual BOOL OnInitDialog();
    afx_msg void OnButtonGetCode();
 afx_msg void OnContextMenu(CWnd *pWnd,CPoint point);

my message map looks like this:


void CTestAppMFCDlg::OnContextMenu(CWnd *pWnd,CPoint point)
HMENU hmenu;

hmenu = GetSubMenu(m_hTapAndHoldMenu, 0);
TrackPopupMenuEx(hmenu, TPM_LEFTALIGN, point.x, point.y, m_hWnd, NULL);

even when the animation works outside the edit controls the OnContextMenu
event never fires.

1) how do i get the "mouse-down" (WM_LBUTTONDOWN) of the edit controls to
work with tap-and-hold?

2) how do i hookup the OnContextMenu correctly so it fires?


2. IBM hardware and software for video?

3. Get Tap&Hold message?

4. AdAware 6.0 Update

5. Tap and Hold quick tip

6. Pop-up ad/Windows

7. Listview and Tap And Hold

8. Creating A new window in and MDI Application

9. Tap-and-Hold Menus

10. Help: Tap and Hold (Popup) Menu - eVC

11. Tap and hold

12. "TAP & HOLD"

13. Popup menus and tap-hold event in eVB?