DOCX

hands-on lab: Multitouch WMTouch with MFC - Native

By Jose Stewart,2014-09-22 12:07
13 views 0
hands-on lab: Multitouch WMTouch with MFC - Native

Hands-On Lab

    Multitouch WMTouch with MFC - Native

Lab version: 1.0.0

    Last updated: 9/22/2011

Native Multitouch HOL

CONTENTS

    OVERVIEW ............................................................................................................................................. 3

    EXERCISE 1: BUILD A MULTITOUCH APPLICATION .......................................................................... 5

    Task 1 Prepare the Application ...................................................................................................... 5

    Task 2 Add Touch Support to the application ................................................................................ 9

    Task 3 Add the Stroke Source and Header Files to the Project, and Draw Lines with your Fingers 12 SUMMARY ............................................................................................................................................ 17

    2

Native Multitouch HOL

Overview

    Windows 7 gives users the ability to manage applications with the touch of their fingers, using no

    intermediate device. This expands the stylus-based capabilities of tablet PCs. Unlike other pointing

    devices, this new capability allows multiple input events 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.

    MFC in Visual Studio 2010 has added support for checking Multitouch hardware readiness and simplified the process of receiving touch events.

    Objectives

    In this Hands-On Lab, you will learn how to manage Multitouch events, including:

    ; Processing input from Windows Touch

    ; Understanding the implications of manipulating multiple touch events simultaneously

    ; Checking for Multitouch hardware existence and readiness

System Requirements

    You must have the following items to complete this lab:

    ; Windows 7

    ; Microsoft Visual Studio 2010

    ; A Multitouch hardware device

Introduction

    To create a Multitouch driven application you can choose one of three approaches: Good, Better, and Best.

    The “Good” approach is the easiest of the three. You should design your application user interface with touch ability in mind. Use large and clean Win32 based controls that make a natural interface for better user experience. Touch abilities such as scrolling come from the Win32 controls. There is no need for extra work. For example, try to scroll the document that you are reading now with your fingers! This is the “Good” approach.

    3

Native Multitouch HOL

    The "Better" approach lets the system receive various low-level touch events and passes the result of the heuristics that the system performs with these events to your application as “gestures”. For example,

    if the user makes a rotation movement on the screen, the system will issue a rotation gesture event with the rotation angle. Although the "Better" approach is easy to use, it has its limitations. Using gestures one cannot get Rotate, Translate, and Scale simultaneously. Also you cannot handle many different touch-based actions at the same time. For example two users that operate different areas of the Window.

    The “Best” approach is to read the low-level touch events as the input to the application. Applications like “Piano” or complex controls like multiple sliders that can be operated simultaneously are good

    examples. For example, run MS Paint, select a drawing tool from the gallery and draw with four of your fingers.

In this Hands-On Lab, you will mimic the new MS Paint Multitouch painting feature using the “Best

    approach. We will read and use the raw touch events.

    About the Multitouch Scratchpad Application

    The Multitouch Scratchpad application presents a simple window that allows simultaneously drawing of continuous lines with your fingers. While the folder Source\MFC_WMTouchSource\Starter contains

    files needed for the exercise, Source\MFC_WMTouchSource\Final contains the completed solution.

    4

Native Multitouch HOL

    Exercise 1: Build a Multitouch Application

Task 1 Prepare the Application

    1. Start Visual Studio 2010

    2. Create a new MFC application project and give it the name ScratchPad:

    3. In the Application Type, select Single Document. To keep the application simple, unselect the

    other options in the dialog similar to the screens-shown below:

    5

Native Multitouch HOL

6

Native Multitouch HOL

7

Native Multitouch HOL

4. Continue clicking Next until you finally hit Finish:

8

Native Multitouch HOL

Task 2 Add Touch Support to the application

    The application that we are building requires touch-enabled hardware, so we need to make this check in the application.

    1. In Scratchpad.cpp, add the following check at the end of

    CScratchPadApp::InitInstance():

    C++

    BYTE digitizerStatus = (BYTE) GetSystemMetrics(SM_DIGITIZER);

    if ((digitizerStatus & (0x80 + 0x40)) == 0) //Stack Ready + MultiTouch

    {

     AfxMessageBox(L"No touch input is currently available.");

     return FALSE;

    }

    9

    Native Multitouch HOL

BYTE nInputs = (BYTE) GetSystemMetrics(SM_MAXIMUMTOUCHES);

CString str;

    str.Format(L"Touch input available with %d touch points.", nInputs);

    AfxMessageBox(str);

return TRUE;

    2. You can see that besides checking for touch availability and readiness we also find out the

    number of touch inputs that the hardware supports.

    3. Compile and run.

    4. Depending on the number of touch inputs you have on your machine, you should see output

    similar to this:

    5. In order to register the application client view window to receive Touch messages, we need to call the MFC function CWnd::RegisterTouchWindow(). We’ll do so after the view has been

    created; i.e. in the OnCreate() event handler.

    10

Report this document

For any questions or suggestions please email
cust-service@docsford.com