0

I am working on an app for Windows that supports multitouch. I have followed the guide found here

http://msdn.microsoft.com/en-us/library/windows/desktop/dd744775(v=vs.85).aspx

but i have a problem. At some point there is a stuck finger meaning that i can see that there is a TOUCHEVENTF_DOWN, a TOUCHEVENTF_MOVE but NO TOUCHEVENTF_UP for this finger although there is no fingers any more on the screen...

I have:

static int fingers = 0;
static LRESULT OnTouch(HWND hWnd, WPARAM wParam, LPARAM lParam );
static LRESULT CALLBACK winProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);

SetWindowLongPtr(handle, GWL_WNDPROC, (long)winProc);

LRESULT CALLBACK winProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam){
    switch(Msg){
    case WM_TOUCH:
        OnTouch(handle, wParam, lParam);
        break;
...
}

LRESULT OnTouch(HWND hWnd, WPARAM wParam, LPARAM lParam )
{
    BOOL bHandled = FALSE;
    UINT cInputs = LOWORD(wParam);
    PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs];
    if (pInputs){
        if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT))){
            for (UINT i=0; i < cInputs; i++){
            TOUCHINPUT ti = pInputs[i];
            if( ti.dwFlags&TOUCHEVENTF_DOWN ) {
                        fingers+=1;
            }
            else {
                if( ti.dwFlags&TOUCHEVENTF_MOVE) {
                }
                if( ti.dwFlags&TOUCHEVENTF_UP) {
                            fingers-=1;
                }
            }
            bHandled = TRUE;
        }else{
            /* handle the error here */
        }
        delete [] pInputs;
    }else{
        /* handle the error here, probably out of memory */
    }
    if (bHandled){
        // if you handled the message, close the touch input handle and return
        CloseTouchInputHandle((HTOUCHINPUT)lParam);
        return 0;
    }else{
        // if you didn't handle the message, let DefWindowProc handle it
        printf("ERROR\n");
        return DefWindowProc(hWnd, WM_TOUCH, wParam, lParam);
    }
}

After touching the screen i end up with no actual fingers on the screen but with the variable fingers != 0....

I would appreciate some help. Thanks.

P.S. I applied the proposed change but i still get stuck fingers, no finger up received.

thodoris
  • 69
  • 8

1 Answers1

2

TOUCHEVENTF_MOVE and TOUCHEVENTF_UP can be combined in the one input, but you are testing for them as if they are exclusive values. Therefore if a 'move' and an 'up' come at the same time you'll miss the 'up'.

The docs for the TOUCHINPUT structure specify which flags make sense in combination.

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79