Gesture Recognizer Examples (Compact 7)
3/12/2014
The following code example shows the functions that a recognizer must export.
Init(void);
ConfigSettings(GESTUREMETRICS * pSettings, BOOL fSet, BOOL fUpdateRegistry);
RecognizeGesture(PCGWETOUCHINPUT pInputs, UINT cInputs);
The gesture core calls the Init function to initialize the recognizer. It calls the ConfigSettings function to provide gesture configuration information obtained from the registry. It calls RecognizeGesture to provide touch events as they occur. These events provide the touch information that the recognizers interpret as gestures. GWETOUCHINPUT is a structure that resembles CETOUCHINPUT.
To cause Compact 7 to load your custom recognizer, provide the name of the DLL in a registry value and its order of execution in registry values, as shown in the following code example.
[HKLM\System\GWE\Recognizers\MyRecognizer]
“DLL”=“MyGestureRgn.dll”
“Order”=DWORD:999
In the following example, a custom gesture recognizer registers a zoom gesture with a gesture type between GID_LAST+1 (13) and GID_MAX (63). The ID values from 1 to 12 are reserved for the built-in recognizer.
When an application receives a gesture message generated by a zoom gesture, it uses the gesture type in the message to identify it as a zoom.
The following code example shows how to call RegisterGesture to register the gesture.
DWORD g_dwZoomGesture = GID_Zoom; // between GID_LAST (12) and GID_MAX (63)
HRESULT APIENTRY Init(void) {
return RegisterGesture(L"MyZoomGesture", &g_dwZoomGesture) ? S_OK : E_FAIL;
}
The gesture core calls a recognizer's RecognizeGesture function to pass touch data to the recognizer. The following code example shows how RecognizerGesture loops through the contact points, examining the flags for each to determine a course of action.
// New touch data
HRESULT APIENTRY RecognizeGesture(PCCETOUCHINPUT pInputs, UINT cInputs)
{
for (UINT c = 0; c < cInputs; ++c) {
if (pInputs[c].dwFlags & TOUCHEVENTF_DOWN)
// Handle initial contact
.
.
.
else if (pInputs[c].dwFlags & TOUCHEVENTF_UP)
// Handle end of contact
.
.
.
else if (pInputs[c].dwFlags & TOUCHEVENTF_MOVE)
// Handle contact point motion
HandleTouchMove(pInputs[c].x, pInputs[c].y);
}
return HRESULT;
}
// Handle contact point motion
void HandleTouchMove(UINT x, UINT y) {
GESTUREINFO gi;
.
.
.
gi.dwID = g_dwZoomGesture;
gi.ullArguments = dwDelta;
Gesture(hwnd, &gi, NULL);
}