本文整理汇总了C++中LPDIRECTINPUTDEVICE8::SetDataFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE8::SetDataFormat方法的具体用法?C++ LPDIRECTINPUTDEVICE8::SetDataFormat怎么用?C++ LPDIRECTINPUTDEVICE8::SetDataFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUTDEVICE8
的用法示例。
在下文中一共展示了LPDIRECTINPUTDEVICE8::SetDataFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: KeyboardInit
BOOL KeyboardInit (HWND hWindow, int iMin, int iMax,
int iDeadZone)
{
if (FAILED(m_lpkDI->CreateDevice (
pdidInstance->guidInstance, m_lpkDKB, NULL)) )
{
return DIENUM_CONTINUE;
}
else
{
return DIENUM_STOP;
}
if (FAILED(m_lpkDKB->SetDataFormat (&c_dfDIKeyboard)))
{
return FALSE;
}
/* Acquire joystick */
HRESULT hRet = m_lpkDKB->Poll ();
if (FAILED (hRet))
{
hRet = m_lpkDKB->Acquire ();
while (hRet == DIERR_INPUTLOST)
{
hRet = m_lpkDKB->Acquire ();
}
}
return TRUE;
}
示例6: INPMouseInit
/////////////////////////////////////
// Name: INPMouseInit
// Purpose: initialize mouse
// if bExclusive, this means
// we don't get actual windows
// mouse location. Use it on
// fullscreen only.
// Output: mouse initialized
// Return: success if so
/////////////////////////////////////
s32 F_API INPMouseInit(void *hMain, u8 bExclusive, iPoint *pBound)
{
INPMouseDestroy();
HRESULT hr;
//create the mouse device
hr = g_pDInput->CreateDevice(GUID_SysMouse, &g_pDMouse, NULL);
if(FAILED(hr))
{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }
//set mouse device as a REAL mouse
hr = g_pDMouse->SetDataFormat(&c_dfDIMouse2);
if(FAILED(hr))
{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }
//set up mouse coop level
u32 coop = g_coopFlag & ~(INP_EXCLUSIVE | INP_NONEXCLUSIVE);
coop |= bExclusive ? INP_EXCLUSIVE : INP_NONEXCLUSIVE;
hr = g_pDMouse->SetCooperativeLevel((HWND)hMain, coop);
if(FAILED(hr))
{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }
//acquire mouse device
g_pDMouse->Acquire();
g_bExclusive = bExclusive;
memset(&g_mouseLoc, 0, sizeof(g_mouseLoc));
INPMouseSetBound(pBound);
return RETCODE_SUCCESS;
}
示例7: InitDinputDevice
//DirectInputデバイスの初期化
bool Application::InitDinputDevice()
{
//DirectInputデバイスを作成
if (FAILED(directInput->CreateDevice(GUID_SysMouse, &dinputDevice, nullptr)))
return false;
//データフォーマットを設定
if (FAILED(dinputDevice->SetDataFormat(&c_dfDIMouse2)))
return false;
//協調モードを設定
if (FAILED(dinputDevice->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
return false;
// 軸モードを設定
DIPROPDWORD diprop;
diprop.diph.dwSize = sizeof(diprop);
diprop.diph.dwHeaderSize = sizeof(diprop.diph);
diprop.diph.dwObj = 0;
diprop.diph.dwHow = DIPH_DEVICE;
diprop.dwData = DIPROPAXISMODE_REL;
if (FAILED(dinputDevice->SetProperty(DIPROP_AXISMODE, &diprop.diph)))
{
MessageBox(NULL, "設定に失敗", "Direct Input Error", MB_OK);
return false;
}
// 入力制御開始
dinputDevice->Acquire();
return true;
}
示例8: DInput_Init_Keyboard
int DInput_Init_Keyboard(void)
{
// this function initializes the keyboard device
// create the keyboard device
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
return(0);
// set cooperation level
if (lpdikey->SetCooperativeLevel(main_window_handle,
DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
return(0);
// set data format
if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
return(0);
// acquire the keyboard
if (lpdikey->Acquire()!=DI_OK)
return(0);
// return success
return(1);
} // end DInput_Init_Keyboard
示例9: 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;
}
示例10: 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
示例11: GetDevice
//------------------------------------------------------
// コントローラー初期化
//------------------------------------------------------
LPDIRECTINPUTDEVICE8 iexInputManager::GetDevice( int n )
{
HRESULT hr;
LPDIRECTINPUTDEVICE8 lpDevice;
// デバイス生成
hr = pDI->CreateDevice( didi[n].guidInstance, &lpDevice, NULL);
if( FAILED(hr) ) return NULL;
if( lpDevice->SetDataFormat( &c_dfDIJoystick2 ) != DI_OK ) return FALSE;
if( lpDevice->SetCooperativeLevel( iexSystem::Window, DISCL_EXCLUSIVE | DISCL_FOREGROUND ) != DI_OK ) return FALSE;
// 自動センタリング無効
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = DIPROPAUTOCENTER_OFF;
lpDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph );
// 各軸設定
lpDevice->EnumObjects(EnumAxes, lpDevice, DIDFT_AXIS);
// 入力制御開始
lpDevice->Acquire();
return lpDevice;
}
示例12: 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 );
}
示例13: 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;
}
示例14: 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
}
示例15: EnumJoysticks
// Called for every enumerated DI device (only vJoy device supported)
// Create a DI device and enumerate the device object - this is to obtain the device ID
// Convert this ID to Unique ID and get the corresponding entry in DB or create one
// - If exists then mark as 'exist' and update DI device
BOOL CvJoyMonitor::EnumJoysticks(const DIDEVICEINSTANCE* pdidInstance)
{
HRESULT hr;
LPDIRECTINPUTDEVICE8 pJoystick;
// If not vJoy device then ignore
if (((pdidInstance)->guidProduct).Data1 != PID2)
return TRUE;
// This is a vJoy device - Create a DI device
hr = m_pDI->CreateDevice( pdidInstance->guidInstance, &pJoystick, NULL );
// If it failed, then we can't use this Joystick. (Maybe the user unplugged
// it while we were in the middle of enumerating it.)
if( FAILED( hr ) )
return DIENUM_CONTINUE;
// 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().
if( FAILED(pJoystick->SetDataFormat( &c_dfDIJoystick2 )))
return TRUE;
// Get device objects and ID
m_CurrentID=0;
if( FAILED(pJoystick->EnumObjects( _EnumObjects, ( VOID* )this, DIDFT_AXIS|DIDFT_BUTTON|DIDFT_POV ) ) )
return TRUE;
// Convert vJoy ID to Unique ID
wstring UniqueID = Convert2UniqueID(m_CurrentID);
// Find device in DB by unique ID
// If found - Update its data
mapDB::iterator iMap;
iMap = m_DeviceDB.find(UniqueID);
if( iMap != m_DeviceDB.end() )
{ // Found
(*iMap).second->Exist=true;
SAFE_RELEASE((*iMap).second->pDeviceDI8);
(*iMap).second->pDeviceDI8=pJoystick;
}
else
{ // Not found - Create
Device * dev = new Device();
dev->UniqueID=UniqueID;
dev->Exist=true;
dev->pDeviceDI8=pJoystick;
dev->isvJoyDevice=true;
dev->RqPolling=false;
dev->ThPolling=NULL;
dev->isPolling=false;
dev->vJoyID = m_CurrentID;
m_DeviceDB.emplace(UniqueID,dev);
};
return TRUE;
}