Getting Started with Windows Touch Gestures
来源:互联网 发布:linux mint安装教程 编辑:程序博客网 时间:2024/06/05 12:07
This section describes the basic steps for using multitouch gestures.
The following steps are typically performed when using Windows Touch gestures:
- Set up a window for receiving gestures.
- Handle the gesture messages.
- Interpret the gesture messages.
Setting up a Window to Receive Gestures
By default, you receive WM_GESTURE messages.
Note If you call RegisterTouchWindow, you will stop receiving WM_GESTURE messages. If you are not receiving WM_GESTURE messages, make sure that you haven't called RegisterTouchWindow.
The following code shows a simple InitInstance implementation.
#include <windows.h>BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){ HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;}
Handling Gesture Messages
Similar to handling Windows Touch input messages, you can handle gesture messages in many ways. If you are using Win32, you can check for the WM_GESTURE message in WndProc. If you are creating another type of application, you can add the WM_GESTURE message to the message map and then implement a custom handler.
The following code shows how gesture messages could be handled.
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; switch (message) { case WM_GESTURE: // Insert handler code here to interpret the gesture. return DecodeGesture(hWnd, message, wParam, lParam);
Interpreting the Gesture Messages
The GetGestureInfo function is used to interpret a gesture message into a structure describing the gesture. The structure, GESTUREINFO, has information about the gesture such as the location where the gesture was performed and the type of gesture. The following code shows how you can retrieve and interpret a gesture message.
LRESULT DecodeGesture(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ // Create a structure to populate and retrieve the extra message info. GESTUREINFO gi; ZeroMemory(&gi, sizeof(GESTUREINFO)); gi.cbSize = sizeof(GESTUREINFO); BOOL bResult = GetGestureInfo((HGESTUREINFO)lParam, &gi); BOOL bHandled = FALSE; if (bResult){ // now interpret the gesture switch (gi.dwID){ case GID_ZOOM: // Code for zooming goes here bHandled = TRUE; break; case GID_PAN: // Code for panning goes here bHandled = TRUE; break; case GID_ROTATE: // Code for rotation goes here bHandled = TRUE; break; case GID_TWOFINGERTAP: // Code for two-finger tap goes here bHandled = TRUE; break; case GID_PRESSANDTAP: // Code for roll over goes here bHandled = TRUE; break; default: // A gesture was not recognized break; } }else{ DWORD dwErr = GetLastError(); if (dwErr > 0){ //MessageBoxW(hWnd, L"Error!", L"Could not retrieve a GESTUREINFO structure.", MB_OK); } } if (bHandled){ return 0; }else{ return DefWindowProc(hWnd, message, wParam, lParam); } }
- Getting Started with Windows Touch Gestures
- Getting Started with Windows Touch Messages
- Getting Started with Sencha Touch 2
- Windows Touch Gestures Overview
- Getting Started with Windows Live Contacts API
- 第一天(Getting Started with Sencha Touch)
- Getting Started with Smartphone
- Getting Started With JasperReports
- Getting started with OpenCV
- Getting Started with DWR
- Getting Started With JasperReports
- Getting Started with MASM
- Getting started with BlazeDS
- Getting Started with RMAN
- Getting started with LAM
- Getting started with Davinci
- Getting Started with Monkey
- Getting Started with Boost
- Oracle--V$FILESTAT
- MEF
- UVA 11806 容斥原理
- Aptana3 使用不完全指南
- Shell 字符串分割
- Getting Started with Windows Touch Gestures
- HDU 1850 - Being a Good Boy in Spring Festival
- shell编程(一)
- asp.net MVC3,@Html.DropDownList如何设置选中项
- phpcms目录结构
- 如何解决双显卡问题
- jqplot详解
- hdu 3667 费用流
- 物联网操作系统再思考-Hello China操作系统的运营商网络协同机制