Support of the multitouch for MS Windows 7/8

Support of the multi touch for Windows 7/8.

Hello,

I tried to add support for multi touch for cocos2d-x that runs in Windows 7. In principle this feature works, though not as good as I would be desirable. Probably due to the fact that I wasn’t familiar with the architecture of the system. Perhaps someone could make code given below better or tell me how to do it.

Changes related to two files:

  1. The counter of touches touchesCounter_ is added to the class CCEGLView.

  2. The following line is added to method bool CCEGLView::Create(...) after creation and resizing of the window:

RegisterTouchWindow(m_hWnd, 0);

  1. The next line is added to the method void CCEGLView::release() before destroying of the window:

UnregisterTouchWindow(m_hWnd);

  1. The processing of messages WM_TABLET_QUERYSYSTEMGESTURESTATUS and WM_TOUCH must be inserted in procedure LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam).

     UINT        cInputs     = 0;
     PTOUCHINPUT pInputs;
     POINT       ptInput;     
    
     case WM_TABLET_QUERYSYSTEMGESTURESTATUS:
    
         return  TABLET_DISABLE_PRESSANDHOLD         |   //  disables press and hold (right-click) gesture
                 TABLET_DISABLE_PENTAPFEEDBACK       |   //  disables UI feedback on pen up (waves)
                 TABLET_DISABLE_PENBARRELFEEDBACK    |   //  disables UI feedback on pen button down (circle)
                 TABLET_DISABLE_FLICKS;                  //  disables pen flicks (back, forward, drag down, drag up)
         break;
    
     case WM_TOUCH:
    
         cInputs = LOWORD(wParam);
         pInputs = new TOUCHINPUT[cInputs];
         if (pInputs)
         {
             if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT)))
             {
                 for (int i = 0; i < static_cast(cInputs); i++)
                 {
                     TOUCHINPUT ti = pInputs[i];                       
                     if (ti.dwID != 0)
                     {                                         
                     //  Do something with your touch input handle
                         ptInput.x = TOUCH_COORD_TO_PIXEL(ti.x);
                         ptInput.y = TOUCH_COORD_TO_PIXEL(ti.y);
                         ScreenToClient(m_hWnd, &ptInput);
                         if (ti.dwFlags & TOUCHEVENTF_UP)
                         {     
                             if (m_bCaptured)
                             {
                                 m_pTouch->SetTouchInfo(0,   (float)((short)ptInput.x - m_rcViewPort.left) / m_fScreenScaleFactor,
                                                             (float)((short)ptInput.y - m_rcViewPort.top) / m_fScreenScaleFactor);
                                 m_pDelegate->touchesEnded(m_pSet, NULL);
                                 m_pSet->removeObject(m_pTouch);
                                 touchesCounter_--;
                                 if (!touchesCounter_)
                                 {
                                     ReleaseCapture();
                                     m_bCaptured = false;
                                 }
                             }
                         }
                         else
                         if (ti.dwFlags & TOUCHEVENTF_DOWN)
                         {
                             if (m_pDelegate && m_pTouch)
                             {
                                 POINT pt = ptInput;
                                 if (PtInRect(&m_rcViewPort, pt))
                                 {
                                     m_bCaptured = true;
                                     touchesCounter_++;
                                     SetCapture(m_hWnd);
                                     m_pTouch->SetTouchInfo(0, (float)(pt.x - m_rcViewPort.left) / m_fScreenScaleFactor,
                                         (float)(pt.y - m_rcViewPort.top) / m_fScreenScaleFactor);
                                     m_pSet->addObject(m_pTouch);
                                     m_pDelegate->touchesBegan(m_pSet, NULL);
                                 }
                             }
                         }
                         else
                         if (ti.dwFlags & TOUCHEVENTF_MOVE)
                         {
                             if (m_bCaptured)
                             {
                                 m_pTouch->SetTouchInfo(0,   (float)((short)ptInput.x - m_rcViewPort.left) / m_fScreenScaleFactor,
                                                             (float)((short)ptInput.y - m_rcViewPort.top) / m_fScreenScaleFactor);
                                 m_pDelegate->touchesMoved(m_pSet, NULL)
                                 ;
                                 DoEvents()
                                 ;
                             }
                         }
                     }
                 }
             }
          // If you handled the message and don't want anything else done with it, you can close it
             CloseTouchInputHandle((HTOUCHINPUT)lParam);
             delete [] pInputs;
         }
         else
         {
         //  TraceLog(_T("******* GetTouchInputInfo Error *******"));
         }
    
         break;  
    
  2. Naturally, you must install Windows 7 SDK for MS Visual Studio and add following references to additional include and library folders in the project libcocos2d:

C:Files\Microsoft SDKs\Windows\v7.0\Include

and

C:Files\Microsoft SDKs\Windows\v7.0\Lib

  1. And of course, I can send the modified files or all project to any email address.

Regards,

Mk


CCEGLView_win32.cpp.zip (6.3 KB)


CCEGLView_win32.h.zip (1.5 KB)


CCEGLView_win32.h.zip (1.7 KB)


CCEGLView_win32.cpp.zip (6.8 KB)

Thanks Michael Kanzieper, awesome job!
I have a question that, how can I test multi-touch in Windows7? Is there any type of multi-touch devices with Windows7 installed? Maybe I’m out.

Hello,

  1. Thanks for reaction.
  2. I’ve checked this feature on Dell Inspiron Duo 1090, HP TouchSmart tx2 and HP Slite 500. On those tablets is pre-installed Windows 7
  3. To check you can choose the “ParticleTest”. When pressed simultaneously on the screen with two fingers you can clearly see the two new birth center of fluctuations. Similarly, as Blackberry Playbook, for instance. But this is a preliminary result. I’ll try to find time to continue this study. I’ve some reasons to use the cocos2dx in their work.

Regards,
Mk

Hi,

In principle, multitouch for Windows 7/8 can be implemented by other way. If we take the method implemented for Blackberry, it will work also. This possibility is realized now. A remark: instead of the using of standard static array, which stores pointers to objects of type CCTouch, I use a special container. The reason is that the pressure identifier in Windows does not match the serial number of the touch. I do not know which way is better, but a choice - it is better than none. Use the macro #EASY_TOUCH_IMPLEMENTATION to select the method of implementation.

And another problem. When you exit the application crash occurs at a destructor ~ParticleDemo() due to the fact that the pointer is null (ParticleTest.cpp). I added an additional check and wrote

if (m_emitter)
{
m_emitter->release();
}

instead of

m_emitter->release();

But maybe it’s a sign of a serious error.

Regards,
Mk

Has anyone looked into this lately? There are a number of touch devices that run on windows now, such as the surface table.