如果要接收并处理触屏消息WM_TOUCH而非WM_GESTURE消息,就要在程序初始化的时候,最好在initinstance中创建窗口之前调用注册触屏消息:
//Register the application window for receiving multi-touch input.
if(!RegisterTouchWindow(GetHWND(), 0))
{
MessageBox(GetHWND(),
L"Cannot register application window for touch input", L"Error", MB_OK);
}
然后就要在消息处理函数那里处理WM_TOUCH消息。
if (uMsg == WM_TOUCH)
{
//A WM_TOUCH message can contain several messages from different contacts
//packed together.
unsigned int numInputs = (int)wParam; //Number of actual contact messages
TOUCHINPUT* ti = new TOUCHINPUT[numInputs]; // Allocate the storage for
//the parameters of the per-
//contact messages
//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)))
{
static CDuiString name;
bool isFirstDown = true;
//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]);
CButtonUI* button = NULL;
button = static_cast<CButtonUI*>(m_PaintManager.FindControl(_T("MainFrame_PresetUpBtn")));
//找到一个down消息就退出循环
if (isFirstDown && button && button->IsVisible())
{
POINT pt = { 0 };
pt.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
pt.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
ScreenToClient(GetHWND(), &pt);
isFirstDown = false;
button = static_cast<CButtonUI*>(m_PaintManager.FindControl(pt));
if (button)
{
name = button->GetName();
}
}
}
else if(ti[i].dwFlags & TOUCHEVENTF_MOVE)
{
//OnTouchMoveHandler(hWnd, ti[i]);
}
else if(ti[i].dwFlags & TOUCHEVENTF_UP)
{
name = _T("");
break;
}
}
}
CloseTouchInputHandle((HTOUCHINPUT)lParam);
delete[] ti;
}
然后在程序退出的时候调用一下
UnregisterTouchWindow
( __in HWND hWnd );就可以了。