本文整理汇总了C++中LPDIRECTINPUT8::CreateDevice方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUT8::CreateDevice方法的具体用法?C++ LPDIRECTINPUT8::CreateDevice怎么用?C++ LPDIRECTINPUT8::CreateDevice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUT8
的用法示例。
在下文中一共展示了LPDIRECTINPUT8::CreateDevice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initDIDevice
bool initDIDevice(HINSTANCE hInstance, HWND hWnd)
{
// Initialisation de DirectInput
if(FAILED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pDI, NULL)))
return false;
// Initialisation du clavier
if(FAILED(g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKeyboardDevice, NULL)))
return false;
if(FAILED(g_pKeyboardDevice->SetDataFormat(&c_dfDIKeyboard)))
return false;
if(FAILED(g_pKeyboardDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
return false;
if(FAILED(g_pKeyboardDevice->Acquire()))
return false;
// Initialisation de la souris
if(FAILED(g_pDI->CreateDevice(GUID_SysMouse, &g_pMouseDevice, NULL)))
return false;
if(FAILED(g_pMouseDevice->SetDataFormat(&c_dfDIMouse)))
return false;
if(FAILED(g_pMouseDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE)))
return false;
if(FAILED(g_pMouseDevice->Acquire()))
return false;
return true;
}
示例2: DirectInput_Init
bool DirectInput_Init(HWND hwnd)
{
//initialize DirectInput object
DirectInput8Create(
GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&dinput,
NULL);
//initialize the keyboard
dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);
dikeyboard->SetDataFormat(&c_dfDIKeyboard);
dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
dikeyboard->Acquire();
//initialize the mouse
dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL);
dimouse->SetDataFormat(&c_dfDIMouse);
dimouse->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
dimouse->Acquire();
d3ddev->ShowCursor(false);
return true;
}
示例3: Initialize
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Summary: Initializes a new input device
Parameters:
[in] pDI – IDirectInput interface
[in] hWnd – Window handle
[in] type – Member of DIRECTINPUTTYPE enum.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
BOOL InputDevice::Initialize( LPDIRECTINPUT8 pDI, HWND hWnd, DIRECTINPUTTYPE type )
{
// Check for a valid parent DIRECTINPUT8 interface
if ( pDI == NULL || type == DIT_FORCE_DWORD )
{
return FALSE;
}
Release();
DIDATAFORMAT* pDataFormat;
m_hWnd = hWnd;
m_type = type;
// Create the device
switch( type )
{
case DIT_KEYBOARD:
if ( FAILED( pDI->CreateDevice( GUID_SysKeyboard, &m_pDevice, NULL ) ) )
{
//SHOWERROR("Unable to create keyboard device.", __FILE__, __LINE__ );
return FALSE;
}
pDataFormat = (DIDATAFORMAT*)&c_dfDIKeyboard;
break;
case DIT_MOUSE:
if ( FAILED( pDI->CreateDevice( GUID_SysMouse, &m_pDevice, NULL ) ) )
{
//SHOWERROR( "Unable to create mouse device.", __FILE__, __LINE__ );
return FALSE;
}
pDataFormat = (DIDATAFORMAT*)&c_dfDIMouse;
break;
default:
return FALSE;
}
// Set the data format
if( FAILED( m_pDevice->SetDataFormat( pDataFormat ) ) )
{
//SHOWERROR( “Unable to set input data format.", __FILE__, __LINE__ );
return FALSE;
}
// Set the cooperative level
if( FAILED( m_pDevice->SetCooperativeLevel( hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE ) ) )
{
//SHOWERROR( “Unable to set input cooperative level.", __FILE__, __LINE__ );
return FALSE;
}
// Acquire the device
if( FAILED( m_pDevice->Acquire() ) )
{
//SHOWERROR("Unable to acquire the input device.", __FILE__, __LINE__ );
return FALSE;
}
return TRUE;
}
示例4: 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;
}
示例5: Init_DirectInput
int Init_DirectInput(HWND hwnd)
{
HRESULT result = DirectInput8Create(
GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&dinput,
NULL);
result = dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL);
result = dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);
return 1;
}
示例6: InitDirectInput
int InitDirectInput (HWND hWnd) {
HRESULT hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&dinput, NULL);
if (hr != DI_OK)
return 0;
hr = dinput->CreateDevice(GUID_SysMouse, &diMouse, NULL);
if (hr != DI_OK)
return 0;
hr = dinput->CreateDevice(GUID_SysKeyboard, &diKeyboard, NULL);
if (hr != DI_OK)
return 0;
return 1;
}
示例7: EnumJoysticksCallback
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext )
{
LPDIRECTINPUTDEVICE8 dinJoystick;
// Obtain an interface to the enumerated joystick.
HRESULT hr = din->CreateDevice( pdidInstance->guidInstance, &dinJoystick, NULL );
if ( FAILED( hr ) )
return ( DIENUM_CONTINUE );
dinJoystick->SetDataFormat( &c_dfDIJoystick2 );
HWND hWnd = *( (HWND*)pContext );
dinJoystick->SetCooperativeLevel( hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND );
unsigned char i = numJoysticks++;
dinJoysticks[i] = dinJoystick;
unsigned int nameLength = strlenW( pdidInstance->tszInstanceName );
char* name = (char*)malloc( nameLength + 1 );
//memcpy( name, pdidInstance->tszInstanceName, nameLength + 1 );
copyWideStringToString( pdidInstance->tszInstanceName, name );
joystickNames[i] = name;
numButtons[i] = 0;
buttonNames[i] = (char**)malloc( 256 );
dinJoystick->EnumObjects( &EnumButtonsCallback, &i, DIDFT_BUTTON );
//return ( DIENUM_STOP );
return ( DIENUM_CONTINUE );
}
示例8: Init
/// a function that Initializes all direct input stuff
void TSRInputSubSystem::Init()
{
#if defined( WIN32 ) || defined( WIN64 )
if ( FAILED( DirectInput8Create( GetModuleHandle( 0 ), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_lpdi, NULL) ) )
{
TSRFatalError( "Error Creating main direct input object" );
}
if ( FAILED( m_lpdi->CreateDevice( GUID_SysMouse, &m_lpdimouse, NULL ) ) )
{
TSRFatalError( "Error Creating mouse device" );
}
if ( FAILED( m_lpdimouse->SetCooperativeLevel( NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ) ) )
{
TSRFatalError( "Error Setting mouse cooperative level" );
}
if ( FAILED( m_lpdimouse->SetDataFormat( &c_dfDIMouse ) ) )
{
TSRFatalError( "Error setting mouse data fromat" );
}
if ( FAILED ( m_lpdimouse->Acquire() ) )
{
TSRFatalError( "error aquiring mouse" );
}
#endif
}
示例9: EnumJoyCallback
//=============================================================================
// ジョイパッド問い合わせ用コールバック関数
//=============================================================================
BOOL CALLBACK EnumJoyCallback(const DIDEVICEINSTANCE* lpddi, VOID* pvRef)
{
DIDEVCAPS diDevCaps; // デバイス情報
// ジョイパッド用デバイスオブジェクトを作成
if(FAILED(g_pInput->CreateDevice(lpddi->guidInstance, &g_pDIDevJoypad[g_nJoypadNum], NULL)))
return DIENUM_CONTINUE; // 列挙を続ける
// ジョイパッドの能力を調べる
diDevCaps.dwSize = sizeof(DIDEVCAPS);
if(FAILED(g_pDIDevJoypad[g_nJoypadNum]->GetCapabilities(&diDevCaps)))
{
if(g_pDIDevJoypad[g_nJoypadNum])
g_pDIDevJoypad[g_nJoypadNum]->Release();
g_pDIDevJoypad[g_nJoypadNum] = NULL;
return DIENUM_CONTINUE; // 列挙を続ける
}
// 規定数に達したら終了
g_nJoypadNum++;
if(g_nJoypadNum == MAX_CONTROLER)
return DIENUM_STOP; // 列挙を終了する
else
return DIENUM_CONTINUE; // 列挙を続ける
}
示例10: Init
//=============================================================================
// 初期化
//=============================================================================
HRESULT CKeyboard::Init(LPDIRECTINPUT8 DInput,HINSTANCE hInstance,HWND hWnd)
{
HRESULT hr;
// デバイスオブジェクトを作成
hr = DInput->CreateDevice(GUID_SysKeyboard,&InputDevice,NULL);
if (FAILED(hr))
{
MessageBox(NULL,"デバイスオブジェクトの作成に失敗しました","ERROR!",(MB_ICONERROR | MB_OK));
return hr;
}
// データフォーマットを設定
hr = InputDevice->SetDataFormat(&c_dfDIKeyboard);
if(FAILED(hr))
{
MessageBox(NULL,"データフォーマットの設定に失敗しました","ERROR!",(MB_ICONERROR|MB_OK));
return hr;
}
// 協調モードを設定(フォアグラウンド&非排他モード)
hr = InputDevice->SetCooperativeLevel(hWnd,(DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
if(FAILED(hr))
{
MessageBox(NULL,"強調モードの設定に失敗しました","ERROR!",(MB_ICONERROR|MB_OK));
return hr;
}
// キーボードへのアクセス権を獲得(入力制御開始)
InputDevice->Acquire();
return S_OK;
}
示例11: InitDirectInput
//-----------------------------------------------------------------------------
// Name: InitDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
HRESULT InitDirectInput( HWND hDlg )
{
HRESULT hr;
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )
return hr;
// Retrieve the system mouse
if( FAILED( g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ) ) )
{
MessageBox( NULL, TEXT( "Mouse not found. The sample will now exit." ),
TEXT( "DirectInput Sample" ),
MB_ICONERROR | MB_OK );
EndDialog( hDlg, 0 );
return S_OK;
}
// 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 MouseState structure to IDirectInputDevice::GetDeviceState().
if( FAILED( hr = g_pMouse->SetDataFormat( &g_dfMouse ) ) )
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_pMouse->SetCooperativeLevel( hDlg, DISCL_NONEXCLUSIVE |
DISCL_FOREGROUND ) ) )
return hr;
return S_OK;
}
示例12: DInput_Joystick_EnumCallback
BOOL CALLBACK DInput_Joystick_EnumCallback( const DIDEVICEINSTANCE* instance, VOID* context )
{
if( FAILED( dinput->CreateDevice( instance->guidInstance, &di_joystick[ di_joystick_count ], NULL )) )
return DIENUM_CONTINUE;
if( FAILED( di_joystick[ di_joystick_count ]->SetDataFormat( &c_dfDIJoystick2 )) )
return DIENUM_CONTINUE;
if( FAILED( di_joystick[ di_joystick_count ]->SetCooperativeLevel( di_enum_hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND )) )
return DIENUM_CONTINUE;
/*
DIDEVCAPS capabilities;
// Determine how many axis the joystick has (so we don't error out setting
// properties for unavailable axis)
capabilities.dwSize = sizeof(DIDEVCAPS);
if (FAILED(hr = joystick->GetCapabilities(&capabilities))) {
return hr;
}
*/
if( FAILED( di_joystick[ di_joystick_count ]->EnumObjects( DInput_joystick_enumAxesCallback, NULL, DIDFT_AXIS )) )
return DIENUM_CONTINUE;
// save name
guid_to_string( &instance->guidInstance, di_joystick_guid[ di_joystick_count ] );
di_joystick_count++;
}
示例13: DInput_Init_Mouse
int DInput_Init_Mouse(void)
{
// this function intializes the mouse
// create a mouse device
if (lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL)!=DI_OK)
return(0);
// set cooperation level
// change to EXCLUSIVE FORGROUND for better control
if (lpdimouse->SetCooperativeLevel(main_window_handle,
DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
return(0);
// set data format
if (lpdimouse->SetDataFormat(&c_dfDIMouse)!=DI_OK)
return(0);
// acquire the mouse
if (lpdimouse->Acquire()!=DI_OK)
return(0);
// return success
return(1);
} // end DInput_Init_Mouse
示例14: open_dx_keyboard
C_RESULT open_dx_keyboard(void)
{
HRESULT hr;
HWND hDlg = GetConsoleHwnd();
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
// Create a DInput object
if (g_pDI==NULL)
if( VP_FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )
return hr;
// Create the connection to the keyboard device
g_pDI->CreateDevice(GUID_SysKeyboard, &fDIKeyboard, NULL);
if (fDIKeyboard)
{
fDIKeyboard->SetDataFormat(&c_dfDIKeyboard);
fDIKeyboard->SetCooperativeLevel(hDlg,DISCL_FOREGROUND | DISCL_EXCLUSIVE);
fDIKeyboard->Acquire();
}
return C_OK;
}
示例15: InitKeyboard
//=============================================================================
// キーボードの初期化
//=============================================================================
HRESULT InitKeyboard(HINSTANCE hInst, HWND hWnd)
{
HRESULT hr;
// デバイスオブジェクトを作成
hr = g_pDInput->CreateDevice(GUID_SysKeyboard, &g_pDIDevKeyboard, NULL);
if(FAILED(hr) || g_pDIDevKeyboard == NULL)
{
MessageBox(hWnd, "キーボードがねぇ!", "警告!", MB_ICONWARNING);
return hr;
}
// データフォーマットを設定
hr = g_pDIDevKeyboard->SetDataFormat(&c_dfDIKeyboard);
if(FAILED(hr))
{
MessageBox(hWnd, "キーボードのデータフォーマットを設定できませんでした。", "警告!", MB_ICONWARNING);
return hr;
}
// 協調モードを設定(フォアグラウンド&非排他モード)
hr = g_pDIDevKeyboard->SetCooperativeLevel(hWnd, (DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
if(FAILED(hr))
{
MessageBox(hWnd, "キーボードの協調モードを設定できませんでした。", "警告!", MB_ICONWARNING);
return hr;
}
// キーボードへのアクセス権を獲得(入力制御開始)
g_pDIDevKeyboard->Acquire();
return S_OK;
}