2013-10-01 63 views
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;} 

但在彈鋼琴鍵的第一觸摸播放適當的,但超過1個觸摸玩鋼琴鍵使最後的關鍵在右側,與觸摸位置無關。

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

有人可以請指導我或糾正我請。

回答

0

TOUCHINFO documentation說:

X x座標觸摸輸入的(水平點)。該成員用物理屏幕座標的百分之一像素表示。

您不能從該值中減去在整個像素中測得的值(rect.left),並期望結果有意義。

相關問題