|
|
我想将游戏手柄装上用SDK 9中的例程进行编程,可是系统找到了设备,运行程序却根本不能枚举EnumDevice获得游戏手柄,在控制面板DirectX中还可以对其进行设置,怎么那个Joystick的例程找不到设备呢?部分代码如下,运行弹出“找不到任何设备”
哪位大哥用过的能否提供一个获取游戏手柄的例程源码给我?万分感激!
我的邮箱:i_fuleyou@126.com
hr = DirectInput8Create(g_hinst, DIRECTINPUT_VERSION,IID_IDirectInput8, (void**)&g_pdi, NULL);
if (FAILED(hr)) {
Complain(hwnd, hr, "DirectInputCreate");
return FALSE;
}
/*
* Look for a force feedback joystick we can use for this
* sample program.
*
* Parameters:
*
* DIDEVTYPE_JOYSTICK
*
* Enumerate only joystick devices.
*
* EnumFFJoysticksCallback
*
* Callback function that is called once for
* each force feedback joystick found.
*
* NULL
*
* Context which is passed to the callback function.
*
* DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK
*
* Flags that further restrict the enumeration.
*
* We are interested only in attached joysticks
* which support force feedback.
*/
hr = g_pdi->EnumDevices(DI8DEVTYPE_JOYSTICK,
EnumFFJoysticksCallback,
NULL,
DIEDFL_ATTACHEDONLY);
if (g_pJoystick == NULL) {
Complain(hwnd, hr, "Couldn't find any force feedback joysticks");
return FALSE;
}
/*
* Set the data format to "simple joystick format".
*
* A data format specifies which controls on a device we
* are interested in, and how they should be reported.
*
* This tells DirectInput that we will be passing a
* DIJOYSTATE structure to IDirectInputDevice2::GetDeviceState.
* Even though we won't actually do it in this sample.
* But setting the data format is important so that
* the DIJOFS_* values work properly.
*
* Parameters:
*
* c_dfDIJoystick
*
* Predefined data format which describes
* a DIJOYSTATE structure.
*/
hr = g_pJoystick->SetDataFormat(&c_dfDIJoystick);
if (FAILED(hr)) {
Complain(hwnd, hr, "SetDataFormat");
return FALSE;
}
/*
* Set the cooperativity level to let DirectInput know how
* this device should interact with the system and with other
* DirectInput applications.
*
* Parameters:
*
* DISCL_EXCLUSIVE
*
* Exclusive access is required in order to perform
* force feedback.
*
* DISCL_FOREGROUND
*
* If the user switches away from our application,
* automatically release the joystick back to the system.
*
*/
hr = g_pJoystick->SetCooperativeLevel(hwnd,
DISCL_EXCLUSIVE | DISCL_FOREGROUND);
if (FAILED(hr)) {
Complain(hwnd, hr, "SetCooperativeLevel");
return FALSE;
} |
|