Esempio di Windows Touch Scratchpad (C++)

L'esempio di Windows Touch Scratchpad mostra come usare i messaggi Di Windows Touch per disegnare tracce dei punti tocco a una finestra. La traccia del dito primario, quella che è stata messa per 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.

screenshot che mostra il touch scratchpad di Windows, con scoggli rossi e neri sullo schermo

Per questa applicazione, la finestra viene registrata come finestra di tocco, i messaggi di tocco vengono interpretati per aggiungere punti di tocco agli oggetti tratti e i tratti input penna vengono visualizzati sullo schermo nel gestore dei 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 di tocco per aggiungere punti di tocco ai tratti input penna.

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

Il codice seguente mostra come l'oggetto stroke esegue il rendering dei 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 multi-tocco (WM_TOUCH/C#),Applicazione Scratchpad multi-tocco (WM_TOUCH/C++) , Esempi di tocco di Windows