基于多点触控钢琴对话的应用程序

时间:2013-10-01 06:06:43

标签: visual-c++ mfc multi-touch midi

我已经制作了一个基于对话框的钢琴应用程序,我正在处理多点触控消息。我有两个类一个是CMIDIKeyboard,我在其中处理触摸消息如下

LRESULT CMIDIKeyboard::OnTouchMessage( WPARAM wParam, LPARAM lParam ){
//Insert handler code here to do something with the message or uncomment the following    line to test
 //-------------------saurabh code------------------------------------------------------------------
       UINT  cInputs  = (int) wParam;      // Number of actual per-contact messages
        TOUCHINPUT* pInputs = new TOUCHINPUT[cInputs]; // Allocate the storage for the   parameters of the per-contact messages
        if (pInputs == NULL)
        {

            return 0;
        }
        // Unpack message parameters into the array of TOUCHINPUT structures, each
        // representing a message for one single contact.
        if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT)))
        {
            // For each contact, dispatch the message to the appropriate message
            // handler.
            for (unsigned int i = 0; i < cInputs; i++)
            {
        if (pInputs[i].dwFlags & TOUCHEVENTF_DOWN)
        {
         CPoint point;
             CRect rect;
         GetClientRect(&rect);
         point=CPoint(pInputs[i].x-rect.left,pInputs[i].y-rect.top);
         m_CurrKey= CPianoCtrl::FindKey(point); 
         m_Keys[m_CurrKey]->NoteOn(m_NoteOnColor,rect);
         NotifyNoteOn(m_LowNote+m_CurrKey);  
                     findchords(m_LowNote+m_CurrKey);
                 InvalidateRect(&rect);
             CWnd::OnTouchMessage(wParam,lParam);

                 }
                else if (pInputs[i].dwFlags & TOUCHEVENTF_UP)
                {
                 //MessageBox("touchup!", "touchup!", MB_OK);
         // g_pIManipProc->ProcessUp(pInputs[i].dwID, (FLOAT)pInputs[i].x, (FLOAT)pInputs[i].y);
                } 

                 else if (pInputs[i].dwFlags & TOUCHEVENTF_MOVE)
                {
        //MessageBox("touchmove!", "touchmove!", MB_OK);
                //g_pIManipProc->ProcessMove(pInputs[i].dwID, (FLOAT)pInputs[i].x, (FLOAT)pInputs[i].y);
                }

            }
        }
        else
        {
            // error handling, presumably out of memory
            ASSERT(FALSE && L"Error: failed to execute GetTouchInputInfo");
            delete [] pInputs;
    return 0;
            //break;
        }
        if (!CloseTouchInputHandle((HTOUCHINPUT)lParam))
        {
            // error handling, presumably out of memory
            ASSERT(FALSE && L"Error: failed to execute CloseTouchInputHandle");
            delete [] pInputs;
    return 0;
            //break;
        }
        delete [] pInputs; 
   //--------------------------------------------------------saurabh code ends-----------------
//MessageBox("touch!", "touch!", MB_OK);
return 0;} 

但是在弹奏钢琴键时,第一次触摸正在播放,但钢琴键上弹奏的触摸次数超过1次,无论触摸位置如何,都可以使用右侧的最后一个键。

  //                  ----------------------
  //                  | | || | | | || || | |
  //                  | |_||_| | |_||_||_| |
  //                  |  |  |  |  |  |  |  |
  //                  ----------------------
  //                          ^           ^
                              |           | 
                        one point    More than 
                          touch      one touch

请有人指导我或纠正我。

1 个答案:

答案 0 :(得分:0)

TOUCHINFO documentation说:

  

x 触摸输入的x坐标(水平点)。该成员以物理屏幕坐标的百分之一像素表示。

您无法从此值中减去以整像素(rect.left)衡量的值,并期望结果有意义。