超簡單教學

1. RegisterTouchWindow(hwnd, TWF_FINETOUCH)
註冊事件


2. 寫一個要處理事件的函數
LRESULT OnTouch( HWND hWnd, WPARAM wParam, LPARAM lParam )
{
UINT cInputs = LOWORD(wParam);  //將wParam轉換touch點的數目
PTOUCHINPUT pInputs = new TOUCHINPUT[cInputs]; //產生一組大小為cInputs的PTOUCHINPUT資料結構


if (pInputs)
{
if (GetTouchInputInfo((HTOUCHINPUT)lParam, cInputs, pInputs, sizeof(TOUCHINPUT)))
{
//printf("\n");
Posf2 pos2;
memset(&pos2, 0, sizeof(pos2));
for (int i=0; i !=(cInputs); i++)
{
TOUCHINPUT ti = pInputs[i];
//printf("x:%d y:%d ", ti.x, ti.y);
pos2.b[i] = true;
pos2.p[i].x = ti.x / 100.0f;
pos2.p[i].y = ti.y / 100.0f;
}
m_qPosf2.push_back(pos2);
}


// if you handled the message and don't want anything else done with it, you can close it
CloseTouchInputHandle((HTOUCHINPUT)lParam);
delete [] pInputs;
}
else
{
printf("touch error");
/* handle the error here */
}

// if you handled the message and don't want anything else done with it, you can close it
CloseTouchInputHandle((HTOUCHINPUT)lParam);


// if you didn't handle the message, let DefWindowProc handle:
return DefWindowProc(hWnd, WM_TOUCH, wParam, lParam);
}


3. 在WndProc記得把事件轉呼叫給剛剛寫的函數
LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_TOUCH:
OnTouch(hWnd, wParam, lParam);
break; 

}
return CallWindowProc((WNDPROC)m_wndproc,hWnd, message, wParam, lParam);
}

arrow
arrow
    全站熱搜

    讓地獄深紅的天亮 發表在 痞客邦 留言(0) 人氣()