18 #define DIRECTINPUT_VERSION 0x0800
22#pragma comment(lib,"dinput8.lib")
23#pragma comment(lib,"dxguid.lib")
70 loop ( i, m_deviceSize )
72 m_apDiDevice[i] = NULL;
90 bool Create(DWORD dwDevType, HINSTANCE hInst = NULL)
98 m_hResult = ::DirectInput8Create(hInst, DIRECTINPUT_VERSION,
99 IID_IDirectInput8,
reinterpret_cast<LPVOID*
>(&m_pDiObject), NULL);
100 if ( FAILED(m_hResult) )
105 if ( m_pDiObject->EnumDevices(dwDevType, ms_Callback,
this, DIEDFL_ATTACHEDONLY) != DI_OK )
122 bool Create(
const GUID& guid, HINSTANCE hInst = NULL)
130 m_hResult = ::DirectInput8Create(hInst, DIRECTINPUT_VERSION,
131 IID_IDirectInput8,
reinterpret_cast<LPVOID*
>(&m_pDiObject), NULL);
132 if ( FAILED(m_hResult) )
137 m_hResult = m_pDiObject->CreateDevice(guid, &m_apDiDevice[0], NULL);
138 if ( FAILED(m_hResult) )
174 return m_apDiDevice[index];
181 CComPtr<IDirectInput8> m_pDiObject;
183 CComPtr<IDirectInputDevice8> m_apDiDevice[MAX];
186 static BOOL CALLBACK ms_Callback(
const DIDEVICEINSTANCE* pInst, VOID* pContext)
189 size_t l = P->m_deviceSize;
192 HRESULT hr = P->m_pDiObject->CreateDevice(pInst->guidInstance, &(P->m_apDiDevice[l]), NULL);
196 return DIENUM_CONTINUE;
217template<
typename TYP>
245 bool Initialize(HWND hWnd = NULL, DWORD dwMode = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)
259 if ( hWnd != NULL && FAILED(m_dx[i]->SetCooperativeLevel(hWnd, dwMode)) )
287 if ( FAILED(m_dx[i]->
Acquire()) )
346 const TYP*
Get(INDEX index = 0)
const
350 IDirectInputDevice8* px = m_dx[index];
351 if ( px != NULL && SUCCEEDED(px->GetDeviceState(
sizeof(TYP), &m_state)) )
426 const DIMOUSESTATE2*
Get(INDEX index = 0)
const
428 return _super::Get(index);
443 return _dx.
Create(GUID_SysMouse, hInst);
455 return !! SUCCEEDED(_px->SetDataFormat(&c_dfDIMouse2));
468 DIPROPDWORD diprop = {
sizeof(DIPROPDWORD)};
469 diprop.diph.dwHeaderSize =
sizeof(diprop.diph);
470 diprop.diph.dwHow = DIPH_DEVICE;
471 diprop.dwData = DIPROPAXISMODE_REL;
472 return !! SUCCEEDED(_px->SetProperty(DIPROP_AXISMODE, &diprop.diph));
504 const DIJOYSTATE2*
Get(INDEX index = 0)
const
506 return _super::Get(index);
531 return _dx.
Create(DI8DEVCLASS_GAMECTRL, hInst);
543 return !! SUCCEEDED(_px->SetDataFormat(&c_dfDIJoystick2));
555 TParam p = { _px,
this };
556 return (_px->EnumObjects(ms_EnumObjectsCallback, &p, DIDFT_ALL)) == DI_OK;
564 IDirectInputDevice8* pDev;
568 static BOOL CALLBACK ms_EnumObjectsCallback(
const DIDEVICEOBJECTINSTANCE* pdidoi, LPVOID pContext)
570 TParam* P =
static_cast<TParam*
>(pContext);
571 if ( (pdidoi->dwType & DIDFT_AXIS) != 0 )
574 diprg.diph.dwSize =
sizeof(DIPROPRANGE);
575 diprg.diph.dwHeaderSize =
sizeof(DIPROPHEADER);
576 diprg.diph.dwHow = DIPH_BYID;
577 diprg.diph.dwObj = pdidoi->dwType;
578 diprg.lMin = P->pJoystick->GetStickRange() * -1;
579 diprg.lMax = P->pJoystick->GetStickRange();
581 if ( FAILED(P->pDev->SetProperty(DIPROP_RANGE, &diprg.diph)) )
#define loop(VAR, CNT)
loop構文.
bool IsInRange(INDEX value, size_t size)
[確認] 範囲チェック.
void Zero(V &value)
[設定] ゼロクリア.
HINSTANCE GetInstanceHandleByTnb(EInstanceType type=EI_Process)
[取得] インスタンスハンドル取得.