0

我制作了一个基于对话框的钢琴应用程序,我在其中处理多点触控消息。我有两个类一个是 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;} 

但是在弹奏钢琴键时,第一次触摸弹奏正常,但在钢琴键上弹奏不止一次触摸,无论触摸位置如何,都启用右侧的最后一个键。

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

任何人都可以请指导我或纠正我。

4

1 回答 1

0

TOUCHINFO文档说:

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

您不能从该值中减去以整个像素 ( rect.left) 测量的值并期望结果有意义。

于 2013-10-01T07:47:43.477 回答