本文整理汇总了C++中LPDIRECTINPUTDEVICE8::GetDeviceInfo方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE8::GetDeviceInfo方法的具体用法?C++ LPDIRECTINPUTDEVICE8::GetDeviceInfo怎么用?C++ LPDIRECTINPUTDEVICE8::GetDeviceInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUTDEVICE8
的用法示例。
在下文中一共展示了LPDIRECTINPUTDEVICE8::GetDeviceInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetDeviceInfo
HRESULT _stdcall GetDeviceInfo(LPDIDEVICEINSTANCEW a) {
return RealDevice->GetDeviceInfo(a);
}
示例2: GetInputDevice
// **if passed an existing DirectInputDevice which matches gGuid
// unacquires it, and sets its cooperative level (reinitialize)
// **if the existing device does not match the passed gGuid, the existing device is released
// **if no device was passed or gGuid did not match
// searches for the controller matching gGuid in connected and available devices
// creates a DirectInputDevice
// sets its data format
// sets its cooperative level
// for joysticks, calls EnumSetObjectsAxis for each axis
// GetInputDevice always leaves the returned device in an UNACQUIRED state.
bool GetInputDevice( HWND hWnd, LPDIRECTINPUTDEVICE8 &lpDirectInputDevice, GUID gGuid, DWORD dwDevType, DWORD dwCooperativeLevel )
{
DebugWriteA("GetInputDevice: gGuid is {%08.8lX-%04.4hX-%04.4hX-%02.2X%02.2X-%02.2X%02.2X%02.2X%02.2X%02.2X%02.2X}\n", gGuid.Data1, gGuid.Data2, gGuid.Data3, gGuid.Data4[0], gGuid.Data4[1], gGuid.Data4[2], gGuid.Data4[3], gGuid.Data4[4], gGuid.Data4[5], gGuid.Data4[6], gGuid.Data4[7]);
if( lpDirectInputDevice != NULL)
{
DIDEVICEINSTANCE didDev;
didDev.dwSize = sizeof(DIDEVICEINSTANCE);
lpDirectInputDevice->GetDeviceInfo( &didDev );
if( didDev.guidInstance == gGuid )
{ // we've already gotten this device; unacquire it and initialize
DebugWriteA("GetInputDevice: already created, attempting to reinit\n");
lpDirectInputDevice->Unacquire();
lpDirectInputDevice->SetCooperativeLevel( hWnd, dwCooperativeLevel );
return true;
}
else
ReleaseDevice( lpDirectInputDevice );
}
HRESULT hResult;
LPCDIDATAFORMAT ppDiDataFormat = NULL;
bool Success = false;
switch( LOBYTE(dwDevType) )
{
case DI8DEVTYPE_KEYBOARD:
ppDiDataFormat = &c_dfDIKeyboard;
break;
case DI8DEVTYPE_MOUSE:
ppDiDataFormat = &c_dfDIMouse2;
break;
//case DI8DEVTYPE_GAMEPAD:
//case DI8DEVTYPE_JOYSTICK:
//case DI8DEVTYPE_DRIVING:
//case DI8DEVTYPE_1STPERSON:
//case DI8DEVTYPE_FLIGHT:
default: // assume everything else is a gamepad; probably not the best idea but it works
ppDiDataFormat = &c_dfDIJoystick;
break;
}
bool bDeviceAvailable = false;
VOID* aRef[2] = { &gGuid, &bDeviceAvailable };
// for each available device in our dwDevType category, run EnumIsDeviceAvailable with params "aRef"
g_pDIHandle->EnumDevices( DI8DEVCLASS_ALL, EnumIsDeviceAvailable, (LPVOID)aRef, DIEDFL_ATTACHEDONLY );
if( !bDeviceAvailable )
{
DebugWriteA("GetInputDevice: Device does not appear available\n");
return false;
}
hResult = g_pDIHandle->CreateDevice( gGuid, &lpDirectInputDevice, NULL );
if( SUCCEEDED( hResult ))
{
hResult = lpDirectInputDevice->SetDataFormat( ppDiDataFormat );
hResult = lpDirectInputDevice->SetCooperativeLevel( hWnd, dwCooperativeLevel );
Success = SUCCEEDED( hResult );
if (!Success)
{
DebugWriteA("GetInputDevice: SetCooperativeLevel failed\n");
}
}
else
DebugWriteA("GetInputDevice: CreateDevice failed\n");
if( Success && ( ppDiDataFormat == &c_dfDIJoystick ))
lpDirectInputDevice->EnumObjects( EnumSetObjectsAxis, lpDirectInputDevice, DIDFT_AXIS );
return Success;
}