Capturing Joystick Input
[The feature associated with this page, Joysticks, is a legacy feature. It has been superseded by Windows.Gaming.Input Namespace. Windows.Gaming.Input Namespace has been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use Windows.Gaming.Input Namespace instead of Joysticks, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]
Most of the code controlling the joystick is in the main window function. In the following portion of the message handler, the application calls joySetCapture to capture input from the joystick JOYSTICKID1.
case WM_CREATE:
if(joySetCapture(hWnd, JOYSTICKID1, NULL, FALSE))
{
MessageBeep(MB_ICONEXCLAMATION);
MessageBox(hWnd, "Couldn't capture the joystick.", NULL,
MB_OK | MB_ICONEXCLAMATION);
PostMessage(hWnd,WM_CLOSE,0,0L);
}
break;