处理触屏消息

如果要接收并处理触屏消息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 );就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值