Share via


Gesture Recognizer Examples (Compact 2013)

3/26/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);

To export the functions, use the LIBRARY statement in a module-definition file to name the library, and list the functions in an EXPORTS statement:

LIBRARY  MYTOUCHRECOGNIZER

EXPORTS
      Init
      RecognizeGesture
      ConfigSettings

For more information, see Module-Definition File.

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 2013 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.

#DEFINE  GID_ZOOM  13                    // between GID_LAST (12) and GID_MAX (63)
DWORD    g_dwZoomGesture = GID_ZOOM; 

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);
}

See Also

Concepts

Custom Gesture Recognition