Disabling Press and Hold in Applications Written for Tablet PC
Mark Hopkins
Microsoft Corporation
June 2003
Applies to:
Microsoft® Windows® XP Tablet PC Edition
Summary: Learn how to disable the press and hold system gesture on Windows XP Tablet PC Edition. (4 printed pages)
Contents
Introduction
Setting a Global Atom
Sample Code
Introduction
This article describes how to disable the press and hold system gesture for any application written for Microsoft® Windows® XP Tablet PC Edition. If you can get a handle to the window, you can disable the press and hold gesture. This is useful for applications that have a user interface feature that requires the user to hold down a mouse button for a period of time. For instance, an application may require the user to hold down a button on the screen while recording voice annotations. On the Tablet PC, this behavior may invoke the press and hold gesture, causing the context menu to appear.
This article does not address design issues regarding the use of the press and hold system gesture in applications nor does it address any other system gesture.
Setting a Global Atom
To disable the default behavior of the press and hold gesture, you must set a property associated with the MicrosoftTabletPenServiceProperty atom. Call the Win32 GlobalAddAtom function to get the ID for the MicrosoftTabletPenServiceProperty atom from the Windows global atom table. Once you have the atom ID and the handle of the window for which you wish to disable the gesture, set the property by calling to the Win32 SetProp function. This disables the press and hold gesture. To enable the press and hold gesture, remove the property from the window by calling the Win32 RemoveProp function.
For more information about atoms and atom tables, see Atoms.
Sample Code
C++
The following C++ code toggles the press and hold gesture on and off by setting a window property associated with the MicrosoftTabletPenServiceProperty global atom. Pass the TogglePressAndHold function the handle of the window for which you wish to disable the gesture and a Boolean value indicating if you want to enable (true) or disable (false) the press and hold gesture.
// Toggle the press and hold gesture for the given window
bool TogglePressAndHold(HWND hWnd, bool enable)
{
// The atom identifier and Tablet PC atom
ATOM atomID = 0;
LPCTSTR tabletAtom = "MicrosoftTabletPenServiceProperty";
// Get the Tablet PC atom ID
atomID = GlobalAddAtom(tabletAtom);
// If getting the ID failed, return false
if (atomID == 0)
{
return false;
}
// Enable or disable the press and hold gesture
if (enable)
{
// Try to enable press and hold gesture by
// clearing the window property, return the result
return RemoveProp(hWnd, tabletAtom);
}
else
{
// Try to disable press and hold gesture by
// setting the window property, return the result
return SetProp(hWnd, tabletAtom, (HANDLE)1);
}
}
Visual Basic 6.0
The following Microsoft Visual Basic® 6 code toggles the press and hold gesture on and off by setting a window property associated with the MicrosoftTabletPenServiceProperty global atom. Pass the TogglePressAndHold function the handle of the window for which you wish to disable the gesture and a Boolean value indicating if you want to enable (True) or disable (False) the press and hold gesture.
' Import the necessary Win32 functions
Declare Function GlobalAddAtom Lib "kernel32" Alias _
"GlobalAddAtomA" (ByVal atom As String) As Integer
Declare Function SetProp Lib "user32" Alias _
"SetPropA" (ByVal hWnd As Long, ByVal atom As String, _
ByVal handle As Long) As Boolean
Declare Function RemoveProp Lib "user32" Alias _
"RemovePropA" (ByVal hWnd As Long, ByVal atom As String) As Long
' Toggle the press and hold system gesture for the given window.
Public Function TogglePressAndHold(ByVal hWnd As Long, _
ByVal enable As Boolean) As Boolean
' The atom identifier and Tablet PC atom
Dim atomID As Integer
Dim tabletAtom As String
tabletAtom = "MicrosoftTabletPenServiceProperty"
' Get the Tablet PC atom ID
atomID = GlobalAddAtom(tabletAtom)
' If getting the ID failed, return false
If atomID = 0 Then
TogglePressAndHold = False
Exit Function
End If
' Enable or disable the press and hold gesture
If enable Then
' Try to enable press and hold gesture by
' clearing the window property, return the result
TogglePressAndHold = RemoveProp(hWnd, tabletAtom)
Else
' Try to disable press and hold gesture by
' setting the window property, return the result
TogglePressAndHold = SetProp(hWnd, tabletAtom, 1)
End If
End Function