Condividi tramite


Esempio di Windows Touch Scratchpad (C++)

L'esempio Windows Touch Scratchpad illustra come usare i messaggi Windows Touch per disegnare tracce dei punti di tocco a una finestra. La traccia del dito primario, quella che è stata messa prima sul digitalizzatore, viene disegnata in nero. Le dita secondarie vengono disegnate in sei altri colori: rosso, verde, blu, ciano, magenta e giallo. L'immagine seguente mostra l'aspetto dell'applicazione durante l'esecuzione.

schermata che mostra il touch scratchpad di Windows, con linee ondulate rosse e nere sullo schermo

Per questa applicazione, la finestra viene registrata come finestra touch, i messaggi di tocco vengono interpretati per aggiungere punti di contatto agli oggetti tratto d'inchiostro e i tratti di inchiostro vengono renderizzati sullo schermo nel gestore di messaggi WM_PAINT.

Il codice seguente mostra come la finestra viene registrata come finestra di tocco.

    // Register application window for receiving multitouch input. Use default settings.
    if(!RegisterTouchWindow(hWnd, 0))
    {
        MessageBox(hWnd, L"Cannot register application window for multitouch input", L"Error", MB_OK);
        return FALSE;
    }

Il codice seguente mostra come vengono usati i messaggi touch per aggiungere punti di tocco ai tratti di inchiostro.

        // WM_TOUCH message handlers
        case WM_TOUCH:
            {
                // WM_TOUCH message can contain several messages from different contacts
                // packed together.
                // Message parameters need to be decoded:
                unsigned int numInputs = (unsigned int) wParam; // Number of actual per-contact messages
                TOUCHINPUT* ti = new TOUCHINPUT[numInputs]; // Allocate the storage for the parameters of the per-contact messages
                if(ti == NULL)
                {
                    break;
                }
                // Unpack message parameters into the array of TOUCHINPUT structures, each
                // representing a message for one single contact.
                if(GetTouchInputInfo((HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT)))
                {
                    // For each contact, dispatch the message to the appropriate message
                    // handler.
                    for(unsigned int i=0; i<numInputs; ++i)
                    {
                        if(ti[i].dwFlags & TOUCHEVENTF_DOWN)
                        {
                            OnTouchDownHandler(hWnd, ti[i]);
                        }
                        else if(ti[i].dwFlags & TOUCHEVENTF_MOVE)
                        {
                            OnTouchMoveHandler(hWnd, ti[i]);
                        }
                        else if(ti[i].dwFlags & TOUCHEVENTF_UP)
                        {
                            OnTouchUpHandler(hWnd, ti[i]);
                        }
                    }
                }
                CloseTouchInputHandle((HTOUCHINPUT)lParam);
                delete [] ti;
            }
            break;

Nel codice seguente viene illustrato il modo in cui i tratti input penna vengono disegnati sullo schermo nel gestore di messaggi WM_PAINT.

        case WM_PAINT:
            hdc = BeginPaint(hWnd, &ps);
            // Full redraw: draw complete collection of finished strokes and
            // also all the strokes that are currently in drawing.
            g_StrkColFinished.Draw(hdc);
            g_StrkColDrawing.Draw(hdc);
            EndPaint(hWnd, &ps);
            break;

Nel codice seguente viene illustrato come l'oggetto tratto visualizza i tratti sullo schermo.

void CStroke::Draw(HDC hDC) const
{
    if(m_nCount < 2)
    {
        return;
    }

    HPEN hPen = CreatePen(PS_SOLID, 3, m_clr);
    HGDIOBJ hOldPen = SelectObject(hDC, hPen);
    Polyline(hDC, m_arrData, m_nCount);
    SelectObject(hDC, hOldPen);
    DeleteObject(hPen);
}

esempio di Windows Touch Scratchpad (C#), applicazione Scratchpad multitocco (WM_TOUCH/C#), applicazione Scratchpad multitocco (WM_TOUCH/C++), Windows Touch Samples