Windows 7 gives users the ability to manage applications with the touch of their fingers, without the need of a stylus. This new gesture capability allows multiple input events to occur at the same time from different pointing locations, and it enables complex scenarios, such as managing applications with ten fingers or with multiple simultaneous users. However, to pull this off, we have to adapt our application's user interface and behavior to support this new input model.
In this Hands-On Lab, you will learn how to manage gesture events, including:
Understanding the implications of manipulating an object with gesture events
Checking for Multitouch hardware existence and readiness
Extracting information from the gesture Windows Message
You must have the following items to complete this lab:
Microsoft Visual Studio 2010 Beta 2 (or higher)
A multitouch hardware device
To create a Multitouch driven application you should design your application’s user interface with touch capabilities in mind. For example, the controls you use should be relatively large to support a finger rather than a mouse or stylus. Beyond that you have 3 different approaches you can consider:
Rely upon touch capabilities already a part of existing Win32 controls. For example, Win32 controls already support some touch capabilities such as scrolling without any extra coding in your application. Go ahead and try to scroll the document you are reading using your fingers.
Read and handle low-level touch events and create your own sophisticated touch handling interface. This is the approach used by complex multiple sliders that users can operate simultaneously or by applications like “Piano” or MS Paint. For example, run MS Paint, select a drawing tool from the gallery and draw with four of your fingers (if the hardware permits):
Use the new Multitouch gestures to get touch events to your applications to support custom actions like zoom, rotate, and translate without the need to read and manipulate raw touch events. This is the approach used in this Hands-On Lab.
About the Multitouch Gesture Demo
The Multitouch Gesture demo presents a simple window containing a rectangle that can be modified using Multitouch gestures. Inside the Sources\MFC_GestureDemoSource folder, you can find a Starter folder that contains files you will need during this lab and a finished version of the lab which is located in the Finalfolder.
This application responds to Multitouch gesture input by interacting with a painted rectangle. The rectangle responds to the following gestures:
To translate the image,place one or two fingers in the application window and drag in the direction you want. Make sure to leave a little space between the two fingers so that the touch interface sees them as separate contact points.
Touch the rectangle with two fingers and turn fingers in a circle.
Touch two fingers and move them farther apart or closer together.
Two Finger Tap
Tap once with both fingers to toggle diagonal lines on or off within the red rectangle.
Press and hold one finger, then tap with the other and then remove the first one to change the color of the rectangle.