本文整理汇总了C++中LPDIRECTINPUT8::EnumDevices方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUT8::EnumDevices方法的具体用法?C++ LPDIRECTINPUT8::EnumDevices怎么用?C++ LPDIRECTINPUT8::EnumDevices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUT8
的用法示例。
在下文中一共展示了LPDIRECTINPUT8::EnumDevices方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: refreshDevices
void refreshDevices() {
if (!diAvailable || di == NULL) {
return;
}
// Poll all devices
di->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback, NULL, DIEDFL_ATTACHEDONLY);
}
示例2: initJoysticks
void initJoysticks( HWND hWnd )
{
numJoysticks = 0;
for ( unsigned char i = 0; i < MAX_JOYSTICKS; i++ )
numButtons[i] = 0;
din->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, &hWnd, DIEDFL_ATTACHEDONLY );
}
示例3: InitDirectInput
//-----------------------------------------------------------------------------
// Name: InitDirectInput()
// output: none
// Desc: very similar to microsoft directinput reference code. I added multiple
// joystick enumeration, tho.
//-----------------------------------------------------------------------------
HRESULT InitDirectInput()
{
HRESULT hr;
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
// Create a DInput object
if( FAILED( hr = DirectInput8Create( GetDllHandle(), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) )
{
return hr;
}
// Enumerate all joysticks in the system. this proggy only can use MAXJOYSTICKS.
if( FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL,
EnumJoysticksCallback,
NULL, DIEDFL_ATTACHEDONLY ) ) )
return hr;
// Make sure we got at least one joystick
if( NULL == g_pJoystick[0] )
{
//MessageBox( NULL, TEXT("Joystick not found. plugin will not work"),
// TEXT("Joypad plugin"),
// MB_ICONERROR | MB_OK );
return DIERR_UNPLUGGED;
}
// Set the data format to "simple joystick" - a predefined data format
//
// A data format specifies which controls on a device we are interested in,
// and how they should be reported. This tells DInput that we will be
// passing a DIJOYSTATE2 structure to IDirectInputDevice::GetDeviceState().
// We need to repeat this setup and enumeration for each joystick.
for (int c = 0; (c < MAXJOYSTICKS) && (g_pJoystick[c] != NULL); c++) {
if( FAILED( hr = g_pJoystick[c]->SetDataFormat( &c_dfDIJoystick2 ) ) )
return hr;
// Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications.
//if( FAILED( hr = g_pJoystick->SetCooperativeLevel( hDlg, DISCL_NONEXCLUSIVE |
// DISCL_BACKGROUND ) ) )
if( FAILED( hr = g_pJoystick[c]->SetCooperativeLevel( NULL, DISCL_NONEXCLUSIVE |
DISCL_BACKGROUND ) ) )
return hr;
// Enumerate the joystick objects. The callback function enabled user
// interface elements for objects that are found, and sets the min/max
// values property for discovered axes.
// The callback is run once for each axis object for each joystick.
// c is passed so that the callback knows which joystick to setup
if( FAILED( hr = g_pJoystick[c]->EnumObjects( EnumObjectsCallback,
(VOID*)(&c), DIDFT_AXIS ) ) )
return hr;
}
return S_OK;
}
示例4: initJoysticks
bool initJoysticks( HWND hWnd )
{
if ( FAILED( din->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, &hWnd, DIEDFL_ATTACHEDONLY ) ) )
{
logg( " ERROR: Unable to enumerate joysticks." );
return ( false );
}
return ( true );
}
示例5: GutInputInit
int GutInputInit(void)
{
memset(g_pKeyDownFuncs, 0, sizeof(g_pKeyDownFuncs));
memset(g_pKeyUpFuncs, 0, sizeof(g_pKeyUpFuncs));
memset(g_pKeyPressedFuncs, 0, sizeof(g_pKeyPressedFuncs));
int hr;
HWND hwnd = GutGetWindowHandleWin32();
HINSTANCE hinst = GutGetWindowInstanceWin32();
hr = DirectInput8Create( hinst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pDI, NULL);
if ( FAILED(hr) )
return 0;
// create keyboard device
hr = g_pDI->CreateDevice( GUID_SysKeyboard, &g_pKeyboard, NULL );
if ( FAILED(hr) )
return 0;
if ( g_pKeyboard )
{
g_pKeyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
g_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
g_pKeyboard->Acquire();
}
// create mouse device
hr = g_pDI->CreateDevice(GUID_SysMouse, &g_pMouse, NULL);
if ( FAILED(hr) )
return 0;
if ( g_pMouse )
{
g_pMouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
g_pMouse->SetDataFormat(&c_dfDIMouse2);
g_pMouse->Acquire();
}
GetCursorPos(&g_op);
ScreenToClient(hwnd, &g_op);
g_mouse = g_op;
// create joystick device
hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY);
if ( FAILED(hr) )
return 0;
if ( g_pJoystick )
{
g_pJoystick->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
g_pJoystick->SetDataFormat(&c_dfDIJoystick);
g_pJoystick->Acquire();
}
return 1;
}
示例6: InitDirectInput
//-----------------------------------------------------------------------------
// Name: InitDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
HRESULT InitDirectInput( HWND hDlg )
{
HRESULT hr;
// Setup the g_EffectsList circular linked list
ZeroMemory( &g_EffectsList, sizeof( EFFECTS_NODE ) );
g_EffectsList.pNext = &g_EffectsList;
// Create a DInput object
if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) )
return hr;
// Get the first enumerated force feedback device
if( FAILED( hr = g_pDI->EnumDevices( 0, EnumFFDevicesCallback, 0,
DIEDFL_ATTACHEDONLY |
DIEDFL_FORCEFEEDBACK ) ) )
return hr;
if( g_pFFDevice == NULL )
{
MessageBox( hDlg, _T("No force feedback device found. ")
_T("The sample will now exit."),
_T("ReadFFE"), MB_ICONERROR | MB_OK );
EndDialog( hDlg, 0 );
return S_OK;
}
// Set the data format
if( FAILED( hr = g_pFFDevice->SetDataFormat( &c_dfDIJoystick ) ) )
return hr;
// Set the coop level
if( FAILED( hr = g_pFFDevice->SetCooperativeLevel( hDlg, DISCL_EXCLUSIVE |
DISCL_BACKGROUND ) ) )
return hr;
// Disable auto-centering spring
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = FALSE;
if( FAILED( hr = g_pFFDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph ) ) )
return hr;
// Acquire the device
if( FAILED( hr = g_pFFDevice->Acquire() ) )
return hr;
return S_OK;
}
示例7: main
int main()
{
HRESULT hr;
hr=DirectInput8Create
(GetModuleHandle (NULL), DIRECTINPUT_VERSION, IID_IDirectInput8A,
(VOID**)&gp_DI, NULL);
printf("Devices\n-----------------\n");
hr = gp_DI->EnumDevices(DI8DEVCLASS_ALL,EnumDevicesCallback, NULL, DIEDFL_ALLDEVICES);
memset(&g_ActionFormat, 0, sizeof(g_ActionFormat));
g_ActionFormat.dwSize = sizeof(g_ActionFormat);
g_ActionFormat.dwActionSize = sizeof(DIACTION);
g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_space);
g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
g_ActionFormat.rgoAction = g_commands_space;
g_ActionFormat.guidActionMap = ACTIONMAP_GUID;
g_ActionFormat.dwBufferSize = 32;
g_ActionFormat.dwGenre = DIVIRTUAL_SPACESIM;
printf("Space combat enumeration\n------------\n");
hr=gp_DI->EnumDevicesBySemantics
(NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES );
// if(FAILED(hr)) printf("Failed?\n");
// g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_driving);
// g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
// g_ActionFormat.rgoAction = g_commands_driving;
// g_ActionFormat.dwGenre = DIVIRTUAL_DRIVING_RACE;
// printf("Driving race enumeration\n------------\n");
// hr=gp_DI->EnumDevicesBySemantics
// (NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES);
// if(FAILED(hr)) printf("Failed?\n");
// g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_fps);
// g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
// g_ActionFormat.rgoAction = g_commands_fps;
// g_ActionFormat.dwGenre = DIVIRTUAL_FIGHTING_FPS;
// printf("First person shooter enumeration\n------------\n");
// hr=gp_DI->EnumDevicesBySemantics
// (NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES);
// if(FAILED(hr)) printf("Failed?\n");
return 0;
}
示例8: Init_DInput
void Init_DInput( HINSTANCE hInstance, HWND hWnd )
{
di_enum_hwnd = hWnd;
if( FAILED( DirectInput8Create( hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8,
(void**) &dinput, NULL)) ) {
return;
}
if( hidmouse_api == HIDMOUSE_API_DIRECTINPUT )
{
di_mouse_count = 0;
dinput->EnumDevices( DI8DEVCLASS_POINTER, DInput_Mouse_EnumCallback, NULL, DIEDFL_ATTACHEDONLY );
}
di_joystick_count = 0;
dinput->EnumDevices( DI8DEVCLASS_GAMECTRL, DInput_Joystick_EnumCallback, NULL, DIEDFL_ATTACHEDONLY );
// XP = system keyboard only (!)
if( FAILED( dinput->CreateDevice( GUID_SysKeyboard, &di_keyboard, NULL)) )
return;
if( FAILED( di_keyboard->SetDataFormat( &c_dfDIKeyboard )) )
return;
if( FAILED( di_keyboard->SetCooperativeLevel( hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND )) )
return;
}
示例9: EnumDevices
LPDIRECTINPUTDEVICE8 DI_CLASS::EnumDevices(LPDIRECTINPUT8 pDI)
{
tmp_pDI = pDI;
tmp_Feedback = FALSE;
memset(tmp_device_name, 0, 255);
if( FAILED( pDI->EnumDevices(DI8DEVCLASS_GAMECTRL,
::EnumCallback,
NULL,
DIEDFL_ATTACHEDONLY) ) )
return NULL;
Feedback = tmp_Feedback;
strcpy(JoystickName, tmp_device_name);
return tmp_Device;
}
示例10: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
LogFile("ditool.txt");
setlocale(LC_ALL, "");
hInst = GetModuleHandle(NULL);
HRESULT hr = DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI, NULL);
if (SUCCEEDED(hr)) g_pDI->EnumDevices(DI8DEVCLASS_ALL, EnumDevicesCallback, NULL, DIEDFL_ATTACHEDONLY);
_getch();
return 0;
}
示例11: sizeof
bool CG27::InitializeG27()
{
HRESULT hr;
// Register with the DirectInput subsystem and get a pointer to a IDirectInput interface we can use.
// Create a DInput object
//initialize directinput library
if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )
return false;
LPDIRECTINPUTDEVICE8 joystick;
// Look for the first simple joystick we can find.
if (FAILED(hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, enumCallback,
NULL, DIEDFL_ATTACHEDONLY))) {
return false;
}
if (g_pJoystick == NULL)
{
// ShowMessageBox("g27 not found, please check the connection, exiting........");
qDebug() << "fucklrl";
return false;
}
if (FAILED(hr = g_pJoystick->SetDataFormat(&c_dfDIJoystick2)))
{
// ShowMessageBox(" set g27 data format error, exiting.......");
qDebug() << "fuckld";
return false;
}
g_pJoystick->SetCooperativeLevel(NULL, DISCL_EXCLUSIVE|DISCL_FOREGROUND);
DIDEVCAPS capabilities;
capabilities.dwSize = sizeof(DIDEVCAPS);
g_pJoystick->GetCapabilities(&capabilities);
if (FAILED(hr=g_pJoystick->EnumObjects(enumAxesCallback, NULL, DIDFT_AXIS)))
{
}
qDebug() << "initializing succeeded";
return true;
}
示例12: InitJoystick
void InitJoystick()
{
if(FAILED(DirectInput8Create ( GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**)&gDirectInput, NULL ) ) )
return;
if(FAILED(gDirectInput->EnumDevices( DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback,
NULL, DIEDFL_ATTACHEDONLY ) ) )
return;
if(!gJoystick)
return;
if( FAILED(gJoystick->SetDataFormat( &c_dfDIJoystick2 ) ) )
return;
}
示例13:
unsigned int
Joystick::deviceCount()
{
unsigned int counter = 0;
LPDIRECTINPUT8 di = NULL;
HRESULT hr;
if (SUCCEEDED(hr = DirectInput8Create(GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(VOID**)&di, NULL))) {
di->EnumDevices(DI8DEVCLASS_GAMECTRL, ::countCallback,
&counter, DIEDFL_ATTACHEDONLY);
}
return counter;
}
示例14: InitJoypad
//=============================================================================
// ジョイパッドの初期化
//=============================================================================
HRESULT InitJoypad(HINSTANCE hInstance, HWND hWnd)
{
int nLoop;
HRESULT hr;
// 入力処理の初期化
hr = InitInput(hInstance, hWnd);
if(FAILED(hr))
{
MessageBox(hWnd, "DirectInputオブジェクトが作れねぇ!", "警告!", MB_ICONWARNING);
return hr;
}
// 初期化
for(nLoop = 0; nLoop < MAX_CONTROLER; nLoop++)
g_pDIDevJoypad[nLoop] = NULL;
// デバイスオブジェクトを作成(接続されているジョイパッドを列挙する)
if(FAILED(g_pInput->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoyCallback, NULL, DIEDFL_ATTACHEDONLY)))
return E_FAIL;
// ジョイパッドの数だけ処理
for(nLoop = 0; nLoop < MAX_CONTROLER; nLoop++)
{
// ジョイパッドがない場合はすっ飛ばす
if(g_pDIDevJoypad[nLoop] == NULL)
continue;
// データフォーマットの設定
if(FAILED(g_pDIDevJoypad[nLoop]->SetDataFormat(&c_dfDIJoystick)))
return E_FAIL;
// 協調レベルの設定
if(FAILED(g_pDIDevJoypad[nLoop]->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
return E_FAIL;
// デバイスへの入力制御開始
g_pDIDevJoypad[nLoop]->Acquire();
}
return S_OK;
}
示例15: HasFFEffects
int HasFFEffects(const CKBehaviorContext& behcontext)
{
CKBehavior* beh = behcontext.Behavior;
CKContext* ctx = behcontext.Context;
HWND mWin = (HWND )ctx->GetMainWindow();
DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&g_pDI2, NULL ) ;
// Get the first enumerated force feedback device
g_pDI2->EnumDevices( 0, EnumFFDevicesCallback0, 0, DIEDFL_ATTACHEDONLY | DIEDFL_FORCEFEEDBACK );
if( g_pFFDevice2 == NULL )
beh->ActivateOutput(1);
else
beh->ActivateOutput(0);
FreeDirectInput0();
return CKBR_OK;
}