Windows Touch Scratchpad 範例 (C++)
Windows Touch Scratchpad 範例示範如何使用 Windows Touch 訊息,將觸控點的追蹤繪製到視窗。 第一個放在數位板上的主要手指追蹤會以黑色繪製。 次要手指會以六種其他色彩繪製:紅色、綠色、藍色、青色、magenta 和黃色。 下圖顯示應用程式在執行時的外觀。
針對此應用程式,視窗會註冊為觸控視窗、將觸控訊息解譯為將觸控點新增至筆劃物件,而筆跡筆劃則會轉譯至 WM_PAINT 訊息處理常式中的螢幕。
下列程式碼示範如何將視窗註冊為觸控視窗。
// 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;
}
下列程式碼示範如何使用觸控訊息,將觸控點新增至筆墨筆劃。
// 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;
下列程式碼顯示筆墨筆劃如何繪製至 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;
下列程式碼顯示筆劃物件如何將筆劃轉譯到螢幕。
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);
}
相關主題
Windows Touch Scratchpad 範例 (C#) 、 多點觸控臨時板應用程式 (WM_TOUCH/C#) 、 多點觸控臨時板應用程式 (WM_TOUCH/C++) 、 Windows Touch 範例
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應