Game Development Reference
In-Depth Information
4.
Since
MinGW
does not support the automatic export of
WM_TOUCH
-related routines,
we have to load them manually from
user32.dll
using
GetProcAddress()
. This
is done in the
LoadTouchFuncs()
function, which is deined in the ile
Wrapper_
Windows.cpp
from
1_MultitouchInput
:
static bool LoadTouchFuncs()
{
if ( !CloseTouchInputHandle_Ptr )
{
HMODULE hUser = LoadLibraryA( "user32.dll" );
CloseTouchInputHandle_Ptr =
(CloseTouchInputHandle_func)
GetProcAddress( hUser, "CloseTouchInputHandle" );
GetTouchInputInfo_Ptr = ( GetTouchInputInfo_func )
GetProcAddress( hUser, "GetTouchInputInfo" );
RegisterTouchWindow_Ptr = (RegisterTouchWindow_func)
GetProcAddress( hUser, "RegisterTouchWindow" );
UnregisterTouchWindow_Ptr =
(UnregisterTouchWindow_func)
GetProcAddress( hUser, "UnregisterTouchWindow" );
}
return ( RegisterTouchWindow_Ptr != NULL );
}
5.
Last, we need to declare the
GetTouchPoint()
routine, which converts the
TOUCHPOINT
coordinates to screen pixels, for simplicity a hardcoded window
size of 100 x 100 pixels is used:
static POINT GetTouchPoint(HWND hWnd, const TOUCHINPUT& ti)
{
POINT pt;
pt.x = ti.x / 100;
pt.y = ti.y / 100;
ScreenToClient( hWnd, &pt );
return pt;
}
6.
Now we are ready to implement the multi-touch message handling on Windows. In
our window function, we add a new message handler for the
WM_TOUCH
message,
which contains data for several different touch points packed together. We unpack
the parameters into an array, where each item represents a message for a single
touch:
case WM_TOUCH:
{
unsigned int NumInputs = (unsigned int)wParam;
if ( NumInputs < 1 ) { break; }