本文整理汇总了C++中LPDIRECTINPUT::EnumDevices方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUT::EnumDevices方法的具体用法?C++ LPDIRECTINPUT::EnumDevices怎么用?C++ LPDIRECTINPUT::EnumDevices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUT
的用法示例。
在下文中一共展示了LPDIRECTINPUT::EnumDevices方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ScanJoystickDevices
int CPPJoyJoyDlg::ScanJoystickDevices (void)
{
int JoyCount;
int Count;
int Index;
for (JoyCount=0;JoyCount<(sizeof(did)/sizeof(*did));JoyCount++)
{
if (did[JoyCount])
{
// do we want to unacquire here too??
did[JoyCount]->Release();
}
did[JoyCount]= NULL;
}
memset (JoystickName,0,sizeof(JoystickName));
memset (JoystickGUID,0,sizeof(JoystickGUID));
JoystickCount= 0;
for (Count=0;Count<8;Count++)
{
m_AxisJoy[Count]->ResetContent();
Index= m_AxisJoy[Count]->AddString("<clear>");
m_AxisJoy[Count]->SetItemData(Index,-1);
}
for (Count=0;Count<16;Count++)
{
m_ButJoy[Count]->ResetContent();
Index= m_ButJoy[Count]->AddString("<clear>");
m_ButJoy[Count]->SetItemData(Index,-1);
}
if (di->EnumDevices(DIDEVTYPE_JOYSTICK,DIEnumDevicesProc,NULL,DIEDFL_ALLDEVICES)!=DI_OK)
return 0;
for (JoyCount=0;JoyCount<JoystickCount;JoyCount++)
{
for (Count=0;Count<8;Count++)
{
Index= m_AxisJoy[Count]->AddString(JoystickName[JoyCount]);
m_AxisJoy[Count]->SetItemData(Index,JoyCount);
}
for (Count=0;Count<16;Count++)
{
Index= m_ButJoy[Count]->AddString(JoystickName[JoyCount]);
m_ButJoy[Count]->SetItemData(Index,JoyCount);
}
}
return 1;
}
示例2: InitJoysticks
bool InitJoysticks ()
{
HRESULT hr;
// Enumerate the joystick devices
if (FAILED(hr = pdi->EnumDevices(DIDEVTYPE_JOYSTICK, EnumJoystickProc, NULL, DIEDFL_ATTACHEDONLY)))
TRACE("!!! Failed to enumerate joystick devices (%#08lx)\n", hr);
// Initialise matched joysticks
if (pdidJoystick1) InitJoystick(pdidJoystick1);
if (pdidJoystick2) InitJoystick(pdidJoystick2);
return true;
}
示例3: enumerate
// Hook on joystick
void JoystickHandler::enumerate(LPDIRECTINPUT di, DWORD dwDevType = DI8DEVTYPE_JOYSTICK, LPCDIDATAFORMAT lpdf = &c_dfDIJoystick2, DWORD dwFlags = DIEDFL_ATTACHEDONLY, int maxEntry = 16) {
clear();
entry = new Entry [maxEntry];
this->di = di;
this->maxEntry = maxEntry;
nEntry = 0;
this->lpdf = lpdf;
// Callbacks to DIEnumDevicesCallback_static
di->EnumDevices(dwDevType, DIEnumDevicesCallback_static, this, dwFlags);
this->di = 0;
}
示例4: input_dinput_add_joysticks_to_listbox
/**
* input_dinput_add_joysticks_to_listbox(): Enumerate joysticks and add them to a listbox.
* @param lstBox Listbox to add the joystick information to.
*/
void input_dinput_add_joysticks_to_listbox(HWND lstBox)
{
if (!lpDI || input_dinput_joystick_error)
return;
// Initialize the "Add Joysticks" counter.
input_dinput_add_joysticks_count = 0;
// Enumerate the joysticks to get their names.
// TODO: Somehow add this to the first EnumDevices().
lpDI->EnumDevices(DIDEVTYPE_JOYSTICK,
&input_dinput_callback_add_joysticks_to_listbox,
lstBox, DIEDFL_ATTACHEDONLY);
}
示例5: InitJoysticks
void InitJoysticks(void)
{
HRESULT hr;
GotJoystick = No;
g_pJoystick = NULL;
hr = lpdi->EnumDevices(DIDEVTYPE_JOYSTICK, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY);
if ( FAILED(hr) ) return;
hr = g_pJoystick->SetDataFormat( &c_dfDIJoystick );
if ( FAILED(hr) ) return;
hr = g_pJoystick->SetCooperativeLevel( hWndMain, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
if ( FAILED(hr) ) return;
GotJoystick = Yes;
}
示例6: FillJoystickCombo
// Fill the supplied combo-box with the list of connected joysticks
void Input::FillJoystickCombo (HWND hwndCombo_)
{
HRESULT hr;
if (FAILED(hr = pdi->EnumDevices(DIDEVTYPE_JOYSTICK, EnumJoystickProc, reinterpret_cast<LPVOID>(hwndCombo_), DIEDFL_ATTACHEDONLY)))
TRACE("!!! Failed to enumerate joystick devices (%#08lx)\n", hr);
}
示例7: PisteInput_Alusta_Ohjaimet
bool PisteInput_Alusta_Ohjaimet()
{
//LPDIRECTINPUTDEVICE temp;
if (FAILED(PI_lpdi->EnumDevices(DIDEVTYPE_JOYSTICK, PisteInput_Enum_Ohjaimet, /*&PI_joystickGUID*/NULL, DIEDFL_ATTACHEDONLY))) {
PisteLog_Kirjoita("[Error] Piste Input: Gamepads - Enumerating failed! \n");
return false;
}
for (int i=0; i < PI_MAX_PELIOHJAIMIA; i++)
{
if (PI_joysticks[i].nimi != NULL)
{
if (PisteInput_Alusta_Ohjain(i))
{
PI_joysticks[i].available = true;
}
else
{
PI_joysticks[i].available = false;
}
}
else
PI_joysticks[i].available = false;
}
/*
if (FAILED(PI_lpdi->CreateDevice(PI_joystickGUID, &temp, NULL)))
return false;
if (FAILED(temp->QueryInterface(IID_IDirectInputDevice2,(void**) &PI_lpdijoy)))
return false;
if (FAILED(temp->Release()))
return false;
if (FAILED(PI_lpdijoy->SetCooperativeLevel(PI_main_window_handle, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE )))
return false;
if (FAILED(PI_lpdijoy->SetDataFormat(&c_dfDIJoystick)))
return false;
DIPROPRANGE joy_axis_range;
//Määritellään x-akseli
joy_axis_range.lMin = -PI_OHJAIN_XY;
joy_axis_range.lMax = PI_OHJAIN_XY;
joy_axis_range.diph.dwSize = sizeof(DIPROPRANGE);
joy_axis_range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
joy_axis_range.diph.dwObj = DIJOFS_X;
joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
PI_lpdijoy->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);
//Määritellään y-akseli
joy_axis_range.lMin = -PI_OHJAIN_XY;
joy_axis_range.lMax = PI_OHJAIN_XY;
joy_axis_range.diph.dwSize = sizeof(DIPROPRANGE);
joy_axis_range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
joy_axis_range.diph.dwObj = DIJOFS_Y;
joy_axis_range.diph.dwHow = DIPH_BYOFFSET;
PI_lpdijoy->SetProperty(DIPROP_RANGE, &joy_axis_range.diph);
DIPROPDWORD dead_angle;
dead_angle.diph.dwSize = sizeof(dead_angle);
dead_angle.diph.dwHeaderSize = sizeof(dead_angle.diph);
dead_angle.diph.dwObj = DIJOFS_X;
dead_angle.diph.dwHow = DIPH_BYOFFSET;
dead_angle.dwData = 5000; //= 10%
PI_lpdijoy->SetProperty(DIPROP_DEADZONE, &dead_angle.diph);
dead_angle.diph.dwSize = sizeof(dead_angle);
dead_angle.diph.dwHeaderSize = sizeof(dead_angle.diph);
dead_angle.diph.dwObj = DIJOFS_Y;
dead_angle.diph.dwHow = DIPH_BYOFFSET;
dead_angle.dwData = 5000; //= 10%
PI_lpdijoy->SetProperty(DIPROP_DEADZONE, &dead_angle.diph);
if (FAILED(PI_lpdijoy->Acquire()))
return false;
*/
return true;
}
示例8: input_dinput_init_joysticks
/**
* input_dinput_init_joysticks(): Initialize joysticks.
* @param hWnd Window handle where the joysticks should be acquired initially.
* @return 0 on success; non-zero on error.
*/
int input_dinput_init_joysticks(HWND hWnd)
{
// TODO: Check if joysticks work with DirectInput 3.
if (input_dinput_joystick_error)
return -1;
if (input_dinput_joystick_initialized)
{
// Close and re-initialize joysticks.
for (int i = 0; i < MAX_JOYS; i++)
{
if (input_dinput_joy_id[i])
{
input_dinput_joy_id[i]->Unacquire();
input_dinput_joy_id[i]->Release();
input_dinput_joy_id[i] = NULL;
}
}
input_dinput_joystick_error = false;
input_dinput_num_joysticks = 0;
memset(input_dinput_joy_id, 0x00, sizeof(input_dinput_joy_id));
// Set the cooperative level.
// TODO: If set to DISCL_FOREGROUND, run setCooperativeLevel_Joysticks().
// TODO: If set to DISCL_BACKGROUND, don't run setCooperativeLevel_Joysticks().
// Currently hard-coded for DISCL_BACKGROUND.
//setCooperativeLevel_Joysticks(hWnd);
}
// Joysticks are being initialized.
input_dinput_joystick_initialized = true;
input_dinput_callback_init_joysticks_enum_counter = 0;
HRESULT rval;
rval = lpDI->EnumDevices(DIDEVTYPE_JOYSTICK,
&input_dinput_callback_init_joysticks_enum,
hWnd, DIEDFL_ATTACHEDONLY);
if (rval != DI_OK)
{
input_dinput_joystick_error = true;
// Close all joysticks.
for (int i = 0; i < MAX_JOYS; i++)
{
if (input_dinput_joy_id[i])
{
input_dinput_joy_id[i]->Unacquire();
input_dinput_joy_id[i]->Release();
input_dinput_joy_id[i] = NULL;
}
}
// Reset number of joysticks.
input_dinput_num_joysticks = 0;
LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
"lpDI->EnumDevices() failed. Joysticks will be unavailable.");
// TODO: Error handling.
return -2;
}
// Joysticks initialized.
return 0;
}