|
Processing Joystick Messages
The following example illustrates how an application could respond to joystick
movements and changes in the button states. When the joystick changes
position, the application moves the cursor and, if either button is pressed, draws a
bullet hole on the desktop. When a joystick button is pressed, the application
draws a hole on the desktop and plays a sound continuously until a button is
released. The messages to watch are MM_JOY1MOVE, MM_JOY1BUTTONDOWN, and MM_JOY1BUTTONUP.
case MM_JOY1MOVE : // changed position
if((UINT) wParam & (JOY_BUTTON1 | JOY_BUTTON2))
DrawFire(hWnd);
DrawSight(lParam); // calculates new cursor position
break;
case MM_JOY1BUTTONDOWN : // button is down
if((UINT) wParam & JOY_BUTTON1)
{
PlaySound(lpButton1, SND_LOOP | SND_ASYNC | SND_MEMORY);
DrawFire(hWnd);
}
else if((UINT) wParam & JOY_BUTTON2)
{
PlaySound(lpButton2, SND_ASYNC | SND_MEMORY | SND_LOOP);
DrawFire(hWnd);
}
break;
case MM_JOY1BUTTONUP : // button is up
sndPlaySound(NULL, 0); // stops the sound
break;
Related Links
Software for Delphi and C++ Builder developers
Software for Visual Studio .NET developers
Software for Visual Basic 6 developers
Delphi Tips&Tricks
MegaDetailed.NET
TMS Scripter Studio Pro components for Delphi/C++Builder
More Online Helps
Win32 Programmer's Reference (win32.hlp)
OLE Programmer's Reference (ole.hlp)
Microsoft Windows Pen API Programmer's Reference (penapi.hlp)
Microsoft Windows Sockets 2 Reference (sock2.hlp)
Microsoft Windows Telephony API (TAPI) Programmer's Reference (tapi.hlp)
Unix Manual Pages
|