Windows Touch 便笺簿示例 (MTScratchpadWMTouch)
本节介绍 Windows Touch 便笺簿示例。
Windows Touch 便笺簿示例演示如何使用 Windows Touch 消息在窗口上绘制触控点的踪迹。主手指(最先放置到数字化器上的手指)的踪迹是用黑色绘制的。辅助手指的踪迹用其他六种颜色绘制:红色、绿色、蓝色、蓝绿色、洋红色和黄色。下图演示了应用程序在运行时的可能外观。

对于此应用程序,将窗口注册为触控窗口,解释触控消息以便将触控点添加到笔画对象,并在 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 API的绘图应用示例。该示例通过处理触控输入来绘制不同颜色的笔迹,并展示了如何注册触控窗口、解析触控消息以及绘制笔画。
958

被折叠的 条评论
为什么被折叠?



