游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1336|回复: 0

求救:DirectInput中获取游戏杆设备的问题

[复制链接]

2

主题

3

帖子

0

积分

新手上路

Rank: 1

积分
0
发表于 2004-11-29 17:15:00 | 显示全部楼层 |阅读模式
我想将游戏手柄装上用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;
    }
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-23 11:51

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表