Exercise 1: Build a Multitouch Application
Task 1 – Create the Win32 Application
Task 2 – Test the Existence and Readiness of Multitouch Hardware
Task 3 – Add the Drawing Object Source and Header Files to the Project, and Draw the Rectangle
In the Starter folder, you will find two files: DrawingObject.h and DrawingObject.cpp. Copy them to the project folder and use “Add Existing item…” to add them to the project.
Task 4 – Touch Me Now!
It’s time to begin! By default touch-enabled system provides WM_GESTURE messages to a target Window. This is somewhat similar to mouse and keyboard messages. The system consumes the low level touch input events and calculates the resulting gesture for us. Use the lParam parameter as the handle to extract the gesture information. The GetGestureInfo() API gets the lParam gesture handle and an address of a GESTUREINFO structure variable:
After consuming the information that was delivered by calling the GetGestureInfo() we must call the CloseGestureInfoHandle() to release the memory block that the system allocated.
Two fields are very important when responding to the gesture message. These are dwFlags and dwID. dwID tells us what gesture the user performed: Zoom, Pan, Rotate, and so forth. dwFlags tells us whether this is the first time it informs us about the gesture, or the last time, or if the user removed the fingers from the screen, but an inertia engine continued to issue the gesture messages. There are simple gestures such as "Two Finger Tap" that the application needs to respond to only once; other gestures are a little bit more complicated because they send many messages during the user operation. For these kinds of gestures (Zoom, Rotate, Translate) we need to respond differently depending upon which of these conditions is in play. For Pan and Zoom, we do nothing for the first gesture in the series. The rotate begin message comes with a rotation angle, so we need to rotate the drawing object. Whenever a gesture is not the first in a series we calculate the difference between the last argument and the new argument and extract the Zoom factor, and translate the range or the relative rotation angle. In this way, we can update the application while users touch and move their fingers on the screen.
Task 5 – There Is a Bug There!