Windows 터치 제스처를 사용하여 시작

이 섹션에서는 멀티 터치 제스처를 사용하기 위한 기본 단계를 설명합니다.

다음 단계는 일반적으로 Windows Touch 제스처를 사용할 때 수행됩니다.

  1. 제스처를 받기 위한 창을 설정합니다.
  2. 제스처 메시지를 처리합니다.
  3. 제스처 메시지를 해석합니다.

제스처를 받을 창 설정

기본적으로 WM_GESTURE 메시지를 받습니다.

참고

RegisterTouchWindow를 호출하면 WM_GESTURE 메시지 수신이 중지됩니다. WM_GESTURE 메시지를 받지 못하는 경우 RegisterTouchWindow를 호출하지 않았는지 확인합니다.

 

다음 코드는 간단한 InitInstance 구현을 보여줍니다.

#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;
}

제스처 메시지 처리

Windows Touch 입력 메시지 처리와 마찬가지로 여러 가지 방법으로 제스처 메시지를 처리할 수 있습니다. Win32를 사용하는 경우 WndProc에서 WM_GESTURE 메시지를 검사 수 있습니다. 다른 유형의 애플리케이션을 만드는 경우 메시지 맵에 WM_GESTURE 메시지를 추가한 다음 사용자 지정 처리기를 구현할 수 있습니다.

다음 코드는 제스처 메시지를 처리할 수 있는 방법을 보여줍니다.

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);            

제스처 메시지 해석

GetGestureInfo 함수는 제스처 메시지를 제스처를 설명하는 구조로 해석하는 데 사용됩니다. 구조체 인 GESTUREINFO에는 제스처가 수행된 위치 및 제스처 유형과 같은 제스처에 대한 정보가 있습니다. 다음 코드는 제스처 메시지를 검색하고 해석하는 방법을 보여줍니다.

  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);
    }
  }

Windows 터치 제스처