Multitouch WMTouch with MFCNative.docx

上传人:b****2 文档编号:24099239 上传时间:2023-05-24 格式:DOCX 页数:17 大小:649.84KB
下载 相关 举报
Multitouch WMTouch with MFCNative.docx_第1页
第1页 / 共17页
Multitouch WMTouch with MFCNative.docx_第2页
第2页 / 共17页
Multitouch WMTouch with MFCNative.docx_第3页
第3页 / 共17页
Multitouch WMTouch with MFCNative.docx_第4页
第4页 / 共17页
Multitouch WMTouch with MFCNative.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

Multitouch WMTouch with MFCNative.docx

《Multitouch WMTouch with MFCNative.docx》由会员分享,可在线阅读,更多相关《Multitouch WMTouch with MFCNative.docx(17页珍藏版)》请在冰豆网上搜索。

Multitouch WMTouch with MFCNative.docx

MultitouchWMTouchwithMFCNative

Hands-OnLab

MultitouchWMTouchwithMFC-Native

 

Labversion:

1.0.0

Lastupdated:

9/25/2018

 

CONTENTS

Overview3

Exercise1:

BuildaMultitouchApplication5

Task1–PreparetheApplication5

Task2–AddTouchSupporttotheapplication8

Task3–AddtheStrokeSourceandHeaderFilestotheProject,andDrawLineswithyourFingers11

Summary16

Overview

Windows7givesuserstheabilitytomanageapplicationswiththetouchoftheirfingers,usingnointermediatedevice.Thisexpandsthestylus-basedcapabilitiesoftabletPCs.Unlikeotherpointingdevices,thisnewcapabilityallowsmultipleinputeventsatthesametimefromdifferentpointinglocations,anditenablescomplexscenarios,suchasmanagingapplicationswithtenfingersorwithmultiplesimultaneoususers.However,topullthisoff,wehavetoadaptourapplication'suserinterfaceandbehaviortosupportthisnewinputmodel.

MFCinVisualStudio2010hasaddedsupportforcheckingMultitouchhardwarereadinessandsimplifiedtheprocessofreceivingtouchevents.

Objectives

InthisHands-OnLab,youwilllearnhowtomanageMultitouchevents,including:

ProcessinginputfromWindowsTouch

Understandingtheimplicationsofmanipulatingmultipletoucheventssimultaneously

CheckingforMultitouchhardwareexistenceandreadiness

SystemRequirements

Youmusthavethefollowingitemstocompletethislab:

Windows7

MicrosoftVisualStudio2010Beta2(orlater)

AMultitouchhardwaredevice

Introduction

TocreateaMultitouchdrivenapplicationyoucanchooseoneofthreeapproaches:

Good,Better,andBest.

The“Good”approachistheeasiestofthethree.Youshoulddesignyourapplicationuserinterfacewithtouchabilityinmind.UselargeandcleanWin32basedcontrolsthatmakeanaturalinterfaceforbetteruserexperience.TouchabilitiessuchasscrollingcomefromtheWin32controls.Thereisnoneedforextrawork.Forexample,trytoscrollthedocumentthatyouarereadingnowwithyourfingers!

Thisisthe“Good”approach.

The"Better"approachletsthesystemreceivevariouslow-leveltoucheventsandpassestheresultoftheheuristicsthatthesystemperformswiththeseeventstoyourapplicationas“gestures”.Forexample,iftheusermakesarotationmovementonthescreen,thesystemwillissuearotationgestureeventwiththerotationangle.Althoughthe"Better"approachiseasytouse,ithasitslimitations.UsinggesturesonecannotgetRotate,Translate,andScalesimultaneously.Alsoyoucannothandlemanydifferenttouch-basedactionsatthesametime.ForexampletwousersthatoperatedifferentareasoftheWindow.

The“Best”approachistoreadthelow-leveltoucheventsastheinputtotheapplication.Applicationslike“Piano”orcomplexcontrolslikemultipleslidersthatcanbeoperatedsimultaneouslyaregoodexamples.Forexample,runMSPaint,selectadrawingtoolfromthegalleryanddrawwithfourofyourfingers.

InthisHands-OnLabyouwillmimicthenewMSPaintMultitouchpaintingfeatureusingthe“Best”approach.Wewillreadandusetherawtouchevents.

AbouttheMultitouchScratchpadApplication

TheMultitouchScratchpadapplicationpresentsasimplewindowthatallowssimultaneouslydrawingofcontinuouslineswithyourfingers.WhilethefolderSource\MFC_WMTouchSource\Startercontainsfilesneededfortheexercise,Source\MFC_WMTouchSource\Finalcontainsthecompletedsolution.

Exercise1:

BuildaMultitouchApplication

Task1–PreparetheApplication

1.StartVisualStudio2010

2.CreateanewMFCapplicationprojectandgiveitthenameScratchPad:

3.IntheApplicationType,selectSingleDocument.Tokeeptheapplicationsimple,unselecttheotheroptionsinthedialogsimilartothescreen-shotsbelow:

4.ContinueclickingNextuntilyoufinallyhitFinish:

Task2–AddTouchSupporttotheapplication

5.Theapplicationthatwearebuildingrequirestouch-enabledhardware,soweneedtomakethischeckintheapplication.

6.InScratchpad.cpp,addthefollowingcheckattheendofCScratchPadApp:

:

InitInstance():

C++

BYTEdigitizerStatus=(BYTE)GetSystemMetrics(SM_DIGITIZER);

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

{

AfxMessageBox(L"Notouchinputiscurrentlyavailable.");

returnFALSE;

}

BYTEnInputs=(BYTE)GetSystemMetrics(SM_MAXIMUMTOUCHES);

CStringstr;

str.Format(L"Touchinputavailablewith%dtouchpoints.",nInputs);

AfxMessageBox(str);

returnTRUE;

7.Youcanseethatbesidescheckingfortouchavailabilityandreadinesswealsofindoutthenumberoftouchinputsthatthehardwaresupports.

8.Compileandrun.

9.Dependingonthenumberoftouchinputsyouhaveonyourmachine,youshouldseeoutputsimilartothis:

10.InordertoregistertheapplicationclientviewwindowtoreceiveTouchmessages,weneedtocalltheMFCfunctionCWnd:

:

RegisterTouchWindow().We’lldosoaftertheviewhasbeencreated;i.e.intheOnCreate()eventhandler.

SwitchtotheClassViewandSelecttheCChildViewclass.

InthePropertiespage,gototheMessagepropertysheetandnavigatetoWM_CREATE,thenaddtheOnCreate()messagehandlerfromthedropdownbox:

11.InsidetheCChildView:

:

OnCreate()handlerappendthefollowingcodetoregistertouchinputfortheviewwindow:

C++

if(!

RegisterTouchWindow())

{

ASSERT(FALSE);

}

Note:

CallingCWnd:

:

RegisterTouchWindow()registers(andunregisters)awindowastouchcapable,allowingittoreceivelow-levelWM_TOUCHmessages.

12.Sincewe’veregisteredtheviewtoreceivetouchinput,wemustoverridethehandlerreceivingeachofthetouchmessages:

CWnd:

:

OnTouchInput().

ThishandlerreceivesasingleinputfromWindowsTouchandshouldreturnTRUEiftheapplicationprocessesthismessage;otherwiseFALSE.

13.InChildView.h,addthismethoddeclaration:

C++

//Overrides

protected:

virtualBOOLOnTouchInput(CPointpt,intnInputNumber,intnInputsCount,PTOUCHINPUTpInput);

14.AndinChildView.cpp,providethecorrespondingimplementation:

C++

BOOLCChildView:

:

OnTouchInput(CPointpt,intnInputNumber,intnInputsCount,PTOUCHINPUTpInput)

{

//TODO:

HandleTocuhinputmessageshere

returnFALSE;

}

Task3–AddtheStrokeSourceandHeaderFilestotheProject,andDrawLineswithyourFingers

Wewouldliketouseourfingersasmultipleinputdevices.Wewanttodrawalineforeachfingerthattouchesthescreen.Todothatwearegoingtousetwostrokecollections.Onecollectionholdsthefinishedstrokes(lines)andanothercollectionholdstheongoing,currentlypaintinglines.Eachfingerthattouchesthescreenaddspointstoastrokeinthem_StrkColDrawingcollection.Whenweraisethefingerfromthescreen,wemovethefinger'sstrokefromthem_StrkColDrawingtothem_StrkColFinishedcollection.Inadditionwewantstrokestohavedifferentcolorsifauserisusingtwoormorefingersonamultitouchmonitor.

15.IntheStarterfolderyouwillfindtwofiles:

Stroke.handStroke.cpp.Copythemtotheprojectfolderanduse“AddExistingitem…”toaddthemtotheproject.

16.Similarly,addStrokeCollection.handStrokeCollection.cpptotheproject.

17.Include"Stroke.h"and"StrokeCollection.h"attheendofStdAfx.hheaderfile.

C++

#include"Stroke.h"

#include"StrokeCollection.h"

18.AddtheseprivatemembervariabledefinitionstoChildView.h:

C++

private:

intm_iCurrColor;//Thecurrentstrokecolor

CStrokeCollectionm_StrkColFinished;//Theuserfinishedenteringstrokes

//afteruserliftedhisorherfinger.

CStrokeCollectionm_StrkColDrawing;//TheStrokescollectiontheuseris

//currentlydrawing.

19.Important:

wehavetoinitializethecurrentcolor.We’lldosointheCChildViewconstructorinChildView.cpp:

C++

CChildView:

:

CChildView():

m_iCurrColor(0)

{

}

20.Todrawthefinishedcollection,weaddthefollowingcalltotheendoftheCChildView:

:

OnPaint()handler.Itwilldrawallfinishedstrokes.

C++

m_StrkColFinished.Draw(&dc);

21.WeneedtoprocesseachTouchinputmessagereceived,sowehandleeachoftheeventswe’reinterestedin:

touchinputdown,moveandup.

22.InCChildView.h,declarethefollowingmethods,whichwe’llusetohandledifferenttouchinputevents:

C++

protected:

//Handlersfordifferenttouchinputevents

BOOLOnTouchInputDown(CPointpt,PTOUCHINPUTpInput);

BOOLOnTouchInputMove(CPointpt,PTOUCHINPUTpInput);

BOOLOnTouchInputUp(CPointpt,PTOUCHINPUTpInput);

23.InCChildView.cpp,addtheimplementationofeachofthetouchinputhandlers:

C++

BOOLCChildView:

:

OnTouchInputDown(CPointpt,PTOUCHINPUTpInput)

{

//Createnewstrokeandaddpointtoit.

COLORREFstrokeColor=GetTouchColor((pInput->dwFlags&TOUCHEVENTF_PRIMARY)!

=0);

CStroke*pStrkNew=newCStroke(pInput->dwID,strokeColor);

pStrkNew->Add(pt);

//Addnewstroketothecollectionofstrokesindrawing.

m_StrkColDrawing.Add(pStrkNew);

returnTRUE;

}

BOOLCChildView:

:

OnTouchInputMove(CPointpt,PTOUCHINPUTpInput)

{

//Findthestrokeinthecollectionofthestrokesindrawing.

intstrokeIndex=m_StrkColDrawing.FindStrokeById(pInput->dwID);

if(strokeIndex>=0)

{

CStroke*pStrk=m_StrkColDrawing[strokeIndex];

//Addcontactpointtothestroke

pStrk->Add(pt);

//Drawthelaststroke

pStrk->Draw(GetDC());

}

returnTRUE;

}

BOOLCChildView:

:

OnTouchInputUp(CPointpt,PTOUCHINPUTpInput)

{

//Findthestrokeinthecollectionofthestrokesindrawing.

intstrokeIndex=m_StrkColDrawing.FindStrokeById(pInput->dwID);

if(strokeIndex>=0)

{

CStroke*pStrkCopy=m_StrkColDrawing[strokeIndex];

//Removethisstrokefromthecollectionofstrokesindrawing.

m_StrkColDrawing.RemoveAt

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1