本文整理汇总了C++中DirectInput8Create函数的典型用法代码示例。如果您正苦于以下问题:C++ DirectInput8Create函数的具体用法?C++ DirectInput8Create怎么用?C++ DirectInput8Create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DirectInput8Create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: refresh_gamepads
int refresh_gamepads(HWND hwnd)
{
int test=FALSE;
int i;
LPDIRECTINPUT8 dinp;
SendMessage(hwnd,CB_RESETCONTENT,0,0);
if(test){
DIDEVICEINSTANCE di;
sprintf(di.tszInstanceName,"adaptoid");
for(i=0;i<4;i++){
di.guidInstance.Data1=rand();
enum_gamepads(&di,hwnd);
}
printf("press key\n");
// getkey();
}
else
if(DirectInput8Create(GetModuleHandle(0),DIRECTINPUT_VERSION,&IID_IDirectInput8,(void *)&dinp,0)==DI_OK){
IDirectInput8_EnumDevices(dinp, DI8DEVCLASS_GAMECTRL, enum_gamepads,
hwnd, DIEDFL_ATTACHEDONLY);
}
SendMessage(hwnd,CB_SETCURSEL,0,0);
return TRUE;
}
示例2: test_GetDeviceStatus
static void test_GetDeviceStatus(void)
{
IDirectInput8A *pDI;
HRESULT hr;
hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput8A, (void **)&pDI, NULL);
if (FAILED(hr))
{
win_skip("Failed to instantiate a IDirectInputA instance: 0x%08x\n", hr);
return;
}
hr = IDirectInput8_GetDeviceStatus(pDI, NULL);
ok(hr == E_POINTER, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr);
hr = IDirectInput8_GetDeviceStatus(pDI, &GUID_Unknown);
todo_wine
ok(hr == DIERR_DEVICENOTREG, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr);
hr = IDirectInput8_GetDeviceStatus(pDI, &GUID_SysMouse);
ok(hr == DI_OK, "IDirectInput8_GetDeviceStatus returned 0x%08x\n", hr);
IDirectInput8_Release(pDI);
}
示例3: assert
InputLayer::InputLayer(
HINSTANCE hInst,
HWND hWnd,
bool bExclusive,
bool bUseKeyboard,
bool bUseMouse )
{
m_pKeyboard = NULL;
m_pMouse = NULL;
if( m_pGlobalILayer )
{
assert(false);
}
m_pGlobalILayer = this;
HRESULT hr;
/**
* ´´½¨DI8 ¶ÔÏó
*/
HR(DirectInput8Create( hInst, DIRECTINPUT_VERSION,
IID_IDirectInput8, (void**)&m_pDI, NULL ));
if( bUseKeyboard )
{
m_pKeyboard = new Keyboard( hWnd );
}
if( bUseMouse )
{
m_pMouse = new Mouse( hWnd, bExclusive );
}
}
示例4: DirectInput8Create
bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
{
HRESULT result;
// Initialize the location of the mouse on the screen.
m_mouseX = 0;
m_mouseY = 0;
// Store the screen size which will be used for positioning the mouse cursor.
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
// Initialize the main direct input interface.
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
if(FAILED(result))
{
return false;
}
// Initialize the direct input interface for the keyboard.
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
if(FAILED(result))
{
return false;
}
// Set the data format. In this case since it is a keyboard we can use the predefined data format.
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
if(FAILED(result))
{
return false;
}
// Set the cooperative level of the keyboard to not share with other programs.
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
if(FAILED(result))
{
return false;
}
// Now acquire the keyboard.
result = m_keyboard->Acquire();
if(FAILED(result))
{
return false;
}
// Initialize the direct input interface for the mouse.
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
if(FAILED(result))
{
return false;
}
// Set the data format for the mouse using the pre-defined mouse data format.
result = m_mouse->SetDataFormat(&c_dfDIMouse);
if(FAILED(result))
{
return false;
}
// Set the cooperative level of the mouse to share with other programs.
result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if(FAILED(result))
{
return false;
}
// Acquire the mouse.
result = m_mouse->Acquire();
if(FAILED(result))
{
return false;
}
return true;
}
示例5: GetCPUCaps
//.........这里部分代码省略.........
if (sim_version > ps_version) {
CString msg;
msg.Format("You have chosen to simulate a pixel shader version (PS %s) higher than your hardware supports (PS %s). "
"You can only simulate lower hardware capabilities. The application will continue to use PS %s.",
simulatedPS, hardwarePS, simulatedPS);
MessageBox(NULL, msg, "Simulate shader", MB_OK | MB_ICONEXCLAMATION);
}
else if (sim_version == ps_version) {
CString msg;
msg.Format("You have chosen to simulate the same pixel shader version as your hardware supports (PS %s). "
"The application will continue normally.", hardwarePS);
MessageBox(NULL, msg, "Simulate shader", MB_OK | MB_ICONINFORMATION);
}
else {
CString msg;
msg.Format("You are simulating pixel shader %s capabilites. Your hardware supports pixel shader %s.",
simulatedPS, hardwarePS);
MessageBox(NULL, msg, "Simulate shader", MB_OK | MB_ICONEXCLAMATION);
}
}
}
#endif // shader sims
#endif
// Load the PNG image list
hData = OpenResourceBinary(995, "IMAGEBLOCK", pData, dataSize);
CapReader.ReadImageData(pData, dataSize, imagehandle_to_address);
FreeResource(hData);
#ifdef CONSTRUCT_DIRECTX9
// Initialise DirectInput
if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (void**)&dinput, NULL)))
throw runtime_error("Failed to initialise DirectInput. Please ensure you have DirectX 8 or above installed!");
// Initialize the keyboard
if (FAILED(dinput->CreateDevice(GUID_SysKeyboard, &d_keyboard, NULL)))
throw runtime_error("Failed to initialise DirectInput.");
if (FAILED(d_keyboard->SetDataFormat(&c_dfDIKeyboard)))
throw runtime_error("Failed to initialise DirectInput.");
if (FAILED(d_keyboard->SetCooperativeLevel(hWnds.front(), DISCL_BACKGROUND |
DISCL_NONEXCLUSIVE)))
throw runtime_error("Failed to initialise DirectInput.");
if (FAILED(d_keyboard->Acquire()))
throw runtime_error("Failed to initialise DirectInput.");
// initialize the mouse
if (FAILED(dinput->CreateDevice(GUID_SysMouse, &d_mouse, NULL)))
throw runtime_error("Failed to initialise DirectInput.");
if (FAILED(d_mouse->SetCooperativeLevel(hWnds.front(), DISCL_BACKGROUND |
DISCL_NONEXCLUSIVE)))
throw runtime_error("Failed to initialise DirectInput.");
if (FAILED(d_mouse->SetDataFormat(&c_dfDIMouse)))
throw runtime_error("Failed to initialise DirectInput.");
if (FAILED(d_mouse->Acquire()))
throw runtime_error("Failed to initialise DirectInput.");
inputState.isDirectInput = true;
#endif
示例6: DirectInput8Create
bool Input::init(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
{
HRESULT result;
//store the screen width and height
m_screenWidth = screenWidth;
m_screenHeight = screenHeight;
//init the mouse location
m_mouseX = 0;
m_mouseY = 0;
//init the main direct input interface
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
if (FAILED(result))
{
return false;
}
//init the direct input interface for the keyboard
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
if (FAILED(result))
{
return false;
}
//set the data format, since it is a keyboard use the defualt keyboard format
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
if (FAILED(result))
{
return false;
}
//Set the cooperative level of the keyboard to not share with other programs
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
if (FAILED(result))
{
return false;
}
//now aquire the keyboard
result = m_keyboard->Acquire();
if (FAILED(result))
{
return false;
}
//init the direct input interface for the mouse
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
if (FAILED(result))
{
return false;
}
//set the data format for th mouse to use
result = m_mouse->SetDataFormat(&c_dfDIMouse);
if (FAILED(result))
{
return false;
}
//Aquire the mouse
result = m_mouse->Acquire();
if (FAILED(result))
{
return false;
}
return true;
}
示例7: open_dx_gamepad
C_RESULT open_dx_gamepad(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;
if( g_bFilterOutXinputDevices )
SetupForIsXInputDevice();
DIJOYCONFIG PreferredJoyCfg = {0};
DI_ENUM_CONTEXT enumContext;
enumContext.pPreferredJoyCfg = &PreferredJoyCfg;
enumContext.bPreferredJoyCfgValid = false;
IDirectInputJoyConfig8* pJoyConfig = NULL;
if( VP_FAILED( hr = g_pDI->QueryInterface( IID_IDirectInputJoyConfig8, ( void** )&pJoyConfig ) ) )
return hr;
PreferredJoyCfg.dwSize = sizeof( PreferredJoyCfg );
if( SUCCEEDED( pJoyConfig->GetConfig( 0, &PreferredJoyCfg, DIJC_GUIDINSTANCE ) ) ) // This function is expected to fail if no g_pJoystick is attached
enumContext.bPreferredJoyCfgValid = true;
SAFE_RELEASE( pJoyConfig );
// Look for a simple g_pJoystick we can use for this sample program.
if( VP_FAILED( hr = g_pDI->EnumDevices( DI8DEVCLASS_GAMECTRL,
Enumg_pJoysticksCallback,
&enumContext, DIEDFL_ATTACHEDONLY ) ) )
return hr;
if( g_bFilterOutXinputDevices )
CleanupForIsXInputDevice();
// Make sure we got a g_pJoystick
if( g_pJoystick == NULL )
{
//MessageBox( NULL, TEXT( "Joystick not found." ),
// TEXT( "A.R. Drone"),
// MB_ICONERROR | MB_OK );
// EndDialog( hDlg, 0 );
return C_FAIL;
}
// Set the data format to "simple g_pJoystick" - 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( VP_FAILED( hr = g_pJoystick->SetDataFormat( &c_dfDIJoystick2 ) ) )
return C_FAIL;
// Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications.
if( VP_FAILED( hr = g_pJoystick->SetCooperativeLevel( hDlg , DISCL_EXCLUSIVE |
DISCL_FOREGROUND ) ) )
return C_FAIL;
// Enumerate the g_pJoystick objects. The callback function enabled user
// interface elements for objects that are found, and sets the min/max
// values property for discovered axes.
if( VP_FAILED( hr = g_pJoystick->EnumObjects( EnumObjectsCallback,
( VOID* )hDlg, DIDFT_ALL ) ) )
return C_FAIL;
return C_OK;
}
示例8: Direct3DCreate9
void CDirectXFramework::Init(HWND& hWnd, HINSTANCE& hInst, bool bWindowed)
{
m_hWnd = hWnd;
//////////////////////////////////////////////////////////////////////////
// Direct3D Foundations - D3D Object, Present Parameters, and D3D Device
//////////////////////////////////////////////////////////////////////////
// Create the D3D Object
m_pD3DObject = Direct3DCreate9(D3D_SDK_VERSION);
// create the direct input object
DirectInput8Create(hInst,
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&m_pDInputObject, NULL);
//RECT
// Find the width and height of window using hWnd and GetWindowRect()
RECT rect;
GetWindowRect(hWnd, &rect);
int screenWidth = rect.right - rect.left;
int screenHeight = rect.bottom - rect.top;
// Set D3D Device presentation parameters before creating the device
D3DPRESENT_PARAMETERS D3Dpp;
ZeroMemory(&D3Dpp, sizeof(D3Dpp)); // NULL the structure's memory
D3Dpp.hDeviceWindow = hWnd; // Handle to the focus window
D3Dpp.Windowed = bWindowed; // Windowed or Full-screen boolean
D3Dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // Format of depth/stencil buffer, 24 bit depth, 8 bit stencil
D3Dpp.EnableAutoDepthStencil = TRUE; // Enables Z-Buffer (Depth Buffer)
D3Dpp.BackBufferCount = 1; // Change if need of > 1 is required at a later date
D3Dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // Back-buffer format, 8 bits for each pixel
D3Dpp.BackBufferHeight = screenHeight + 424; // Make sure resolution is supported, use adapter modes
D3Dpp.BackBufferWidth = screenWidth + 224; // (Same as above)
D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Discard back-buffer, must stay discard to support multi-sample
D3Dpp.PresentationInterval = m_bVsync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE; // Present back-buffer immediately, unless V-Sync is on
D3Dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; // This flag should improve performance, if not set to NULL.
D3Dpp.FullScreen_RefreshRateInHz = bWindowed ? 0 : D3DPRESENT_RATE_DEFAULT; // Full-screen refresh rate, use adapter modes or default
D3Dpp.MultiSampleQuality = 0; // MSAA currently off, check documentation for support.
D3Dpp.MultiSampleType = D3DMULTISAMPLE_NONE; // MSAA currently off, check documentation for support.
// Check device capabilities
DWORD deviceBehaviorFlags = 0;
m_pD3DObject->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_D3DCaps);
// Determine vertex processing mode
if(m_D3DCaps.DevCaps & D3DCREATE_HARDWARE_VERTEXPROCESSING)
{
// Hardware vertex processing supported? (Video Card)
deviceBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
else
{
// If not, use software (CPU)
deviceBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
// If hardware vertex processing is on, check pure device support
if(m_D3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE && deviceBehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING)
{
deviceBehaviorFlags |= D3DCREATE_PUREDEVICE;
}
// Create the D3D Device with the present parameters and device flags above
m_pD3DObject->CreateDevice(
D3DADAPTER_DEFAULT, // which adapter to use, set to primary
D3DDEVTYPE_HAL, // device type to use, set to hardware rasterization
hWnd, // handle to the focus window
deviceBehaviorFlags, // behavior flags
&D3Dpp, // presentation parameters
&m_pD3DDevice); // returned device pointer
/*************************************
create the direct input devices here!!
***************************************/
m_pDInputObject->CreateDevice(GUID_SysKeyboard, &m_pDIKeyboard, NULL);
m_pDInputObject->CreateDevice(GUID_SysMouse, &m_pDIMouse, NULL);
//setting data format
m_pDIKeyboard->SetDataFormat(&c_dfDIKeyboard);
m_pDIMouse->SetDataFormat(&c_dfDIMouse2);
//setting cooperative level
m_pDIKeyboard->SetCooperativeLevel(m_hWnd,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
m_pDIMouse->SetCooperativeLevel(m_hWnd,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
// end of direct input****************************************************
// create the SPRITE object
D3DXCreateSprite(m_pD3DDevice, &m_pD3DSprite);
// create a TEXTURE object
D3DXCreateTextureFromFileEx(m_pD3DDevice, L"space.jpg", 0,0,0,0,
D3DFMT_UNKNOWN,D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255),
&m_imageInfo, 0, &mainMenuTexture);
//.........这里部分代码省略.........
示例9: CoInitialize
//.........这里部分代码省略.........
D3DXCreateTextureFromFileEx(m_pD3DDevice, L"wall.tga", 0, 0, 0, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255),
&m_wallImage, 0, &m_wallTexture);
D3DXCreateTextureFromFileEx(m_pD3DDevice, L"START.tga", 0, 0, 0, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255),
&m_StartImage, 0, &m_StartText);
D3DXCreateTextureFromFileEx(m_pD3DDevice, L"CREDITS.tga", 0, 0, 0, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255),
&m_CreditImage, 0, &m_CreditText);
D3DXCreateTextureFromFileEx(m_pD3DDevice, L"CREDIT2.tga", 0, 0, 0, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255),
&m_Credit2Image, 0, &m_Credit2Text);
D3DXCreateTextureFromFileEx(m_pD3DDevice, L"EXIT.tga", 0, 0, 0, 0,
D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT,
D3DX_DEFAULT, D3DCOLOR_XRGB(255, 0, 255),
&m_ExitImage, 0, &m_ExitText);
// multiple times, just call that sprite's Draw() with different
// transformation values.
//Paddle 1
Paddle[0].xp = -12;
Paddle[0].yp = 300;
//Paddle 2
Paddle[1].xp = 800;
Paddle[1].yp = 300;
//Ball
Ball.xp = 400;
Ball.yp = 300;
// Wall / Background
Wall.xp = 400;
Wall.yp = 300;
// Menu
Menu.xp = 200;
Menu.yp = 200;
//Initial Direction
Ball.DIR_UP_RIGHT = true;
//MENU
Menu.onGAME = false;
Menu.onSTART = true;
//*************************************************************************
// create direct input object
DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8,(void **)&m_pDIObject, NULL);
// Create Keyboard
m_pDIObject->CreateDevice(GUID_SysKeyboard, &m_pDIKeyboard, NULL);
//Set Keyboard data format
m_pDIKeyboard->SetDataFormat(&c_dfDIKeyboard);
//Set Keyboard coop level
m_pDIKeyboard->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
// Create Mouse
m_pDIObject->CreateDevice(GUID_SysMouse, &m_pDIMouse, NULL);
// Set Mouse Data Format
m_pDIMouse->SetDataFormat(&c_dfDIMouse2);
// Set Mouse Coop Level
m_pDIMouse->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
//SOUND INITIALIZATION
channel = 0;
result = FMOD::System_Create(&system);
result = system->init(100, FMOD_INIT_NORMAL, 0); // initialize fmod
result = system->createSound("beep1.ogg", FMOD_DEFAULT, 0, &mySound1);
result = system->createSound("beep2.ogg", FMOD_DEFAULT, 0, &mySound2);
result = system->createSound("pongMusic.wav", FMOD_LOOP_NORMAL | FMOD_2D, 0, &myStream);
//BACKGROUND MUSIC---------------------------------------------
result = system->playSound(myStream, 0, true, &channel);
result = channel->setVolume(0.5f);
result = channel->setPaused(false);
//-------------------------------------------------------------
}
示例10: DirectInput8Create
bool InputWrapper::Init(HINSTANCE hinstance, HWND hwnd)
{
if (myIsInitialized == false)
{
myIsInitialized = true;
HRESULT result;
// Initialize the main direct input interface.
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&myDirectInputInterface, NULL);
if (FAILED(result) == true)
{
return false;
}
// Initialize the direct input interface for the keyboard.
result = myDirectInputInterface->CreateDevice(GUID_SysKeyboard, &myKeyboard, NULL);
if (FAILED(result) == true)
{
return false;
}
// Set the data format. In this case since it is a keyboard we can use the predefined data format.
result = myKeyboard->SetDataFormat(&c_dfDIKeyboard);
if (FAILED(result) == true)
{
return false;
}
// Set the cooperative level of the keyboard to not share with other programs.
result = myKeyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE);
if (FAILED(result) == true)
{
return false;
}
// Now acquire the keyboard.
result = myKeyboard->Acquire();
if (FAILED(result) == true)
{
return false;
}
// Initialize the direct input interface for the mouse.
result = myDirectInputInterface->CreateDevice(GUID_SysMouse, &myMouse, NULL);
if (FAILED(result) == true)
{
return false;
}
// Set the data format for the mouse using the pre-defined mouse data format.
result = myMouse->SetDataFormat(&c_dfDIMouse);
if (FAILED(result) == true)
{
return false;
}
// Set the cooperative level of the mouse to share with other programs.
result = myMouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(result) == true)
{
return false;
}
// Acquire the mouse.
result = myMouse->Acquire();
if (FAILED(result) == true)
{
return false;
}
}
return true;
}
示例11: DirectInput8Create
//********************************************************************************************************************************************
// 初期化
//********************************************************************************************************************************************
bool InputManager::Initialize( void )
{
HRESULT hResult = S_OK;
// DirectInputインターフェイスを取得
hResult = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_pInput, NULL );
// マウスデバイスの初期化
if( SUCCEEDED( hResult ) ){
// デバイスを作成
hResult = m_pInput->CreateDevice( GUID_SysMouse, &m_pMouse, NULL );
// データ形式を設定
if( SUCCEEDED( hResult ) ){
hResult = m_pMouse->SetDataFormat( &c_dfDIMouse2 );
}
// 強調レベルの設定
if( SUCCEEDED( hResult ) ){
// 非排他
hResult = m_pMouse->SetCooperativeLevel( iexSystem::Window, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND );
// 排他
//hResult = m_pMouse->SetCooperativeLevel( iexSystem::Window, DISCL_EXCLUSIVE | DISCL_FOREGROUND );
}
// バッファサイズの設定
if( SUCCEEDED( hResult ) ){
DIPROPDWORD dipdw;
// ヘッダー
dipdw.diph.dwSize = sizeof( DIPROPDWORD );
dipdw.diph.dwHeaderSize = sizeof( DIPROPHEADER );
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
// データ
dipdw.dwData = sizeof( DIMOUSESTATE2 );
// セット
hResult = m_pMouse->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph );
}
}
// キーボードデバイスの初期化
if( SUCCEEDED( hResult ) ){
// デバイスを作成
hResult = m_pInput->CreateDevice( GUID_SysKeyboard, &m_pKeyBoard, NULL );
// データ形式を設定
if( SUCCEEDED( hResult ) ){
hResult = m_pKeyBoard->SetDataFormat( &c_dfDIKeyboard );
}
// 強調レベルの設定
if( SUCCEEDED( hResult ) ){
hResult = m_pKeyBoard->SetCooperativeLevel( iexSystem::Window, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND );
}
}
// 結果を返す
if( SUCCEEDED( hResult ) ) return true;
else return false;
}
示例12: PsychHIDInitializeHIDStandardInterfaces
void PsychHIDInitializeHIDStandardInterfaces(void)
{
int i;
HRESULT rc;
HINSTANCE modulehandle = NULL;
dinput = NULL;
ndevices = 0;
// Init x_dev array:
for (i = 0; i < PSYCH_HID_MAX_DEVICES; i++) x_dev[i] = NULL;
// Init keyboard queue arrays:
memset(&psychHIDKbQueueFirstPress[0], 0, sizeof(psychHIDKbQueueFirstPress));
memset(&psychHIDKbQueueFirstRelease[0], 0, sizeof(psychHIDKbQueueFirstRelease));
memset(&psychHIDKbQueueLastPress[0], 0, sizeof(psychHIDKbQueueLastPress));
memset(&psychHIDKbQueueLastRelease[0], 0, sizeof(psychHIDKbQueueLastRelease));
memset(&psychHIDKbQueueActive[0], 0, sizeof(psychHIDKbQueueActive));
memset(&psychHIDKbQueueScanKeys[0], 0, sizeof(psychHIDKbQueueScanKeys));
// We need the module instance handle of ourselves, ie., the PsychHID mex file to
// open a DirectInput-8 interface, so the OS can apply backwards compatibility fixes
// specific to the way our mex file DLL was built. For this we need the name of the
// mex file, which is dependent on Octave vs. Matlab and 32-Bit vs. 64-Bit:
#ifndef PTBOCTAVE3MEX
// Matlab: 64-Bit or 32-Bit mex file?
#if defined(__LP64__) || defined(_M_IA64) || defined(_WIN64)
// 64-Bit:
modulehandle = GetModuleHandle("PsychHID.mexw64");
#else
// 32-Bit:
modulehandle = GetModuleHandle("PsychHID.mexw32");
#endif
#else
// Octave: Same mex file file-extension for 32/64-Bit:
modulehandle = GetModuleHandle("PsychHID.mex");
#endif
// If this doesn't work, try with application module handle as fallback. This works usually on
// Windows XP/Vista/7, but may fail catastrophically on Windows-8 and later:
if (NULL == modulehandle) {
printf("PsychHID-WARNING: Could not get module handle to PsychHID mex file. Did you rename it? Please don't do that!\n");
printf("PsychHID-WARNING: Will try application module handle as fallback. This may end badly, e.g., with a crash. Cross your fingers!\n");
modulehandle = GetModuleHandle(NULL);
}
if (NULL == modulehandle) PsychErrorExitMsg(PsychError_system, "PsychHID: FATAL ERROR: Couldn't get module handle to create interface to Microsoft DirectInput-8! Game over!");
// Open a DirectInput-8 interface:
rc = DirectInput8Create(modulehandle, DIRECTINPUT_VERSION, IID_IDirectInput8, (LPVOID*)&dinput, NULL);
if (DI_OK != rc) {
printf("PsychHID-ERROR: Error return from DirectInput8Create: %x\n", (int) rc);
if (rc == DIERR_OLDDIRECTINPUTVERSION) printf("PsychHID-ERROR: You need to install a more recent version of DirectX -- at least DirectX-8.\n");
PsychErrorExitMsg(PsychError_system, "PsychHID: FATAL ERROR: Couldn't create interface to Microsoft DirectInput-8! Game over!");
}
// Enumerate all DirectInput keyboard(-like) devices:
rc = dinput->EnumDevices(DI8DEVCLASS_KEYBOARD, (LPDIENUMDEVICESCALLBACK) keyboardEnumCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_INCLUDEHIDDEN);
if (DI_OK != rc) {
printf("PsychHID-ERROR: Error return from DirectInput8 EnumDevices(): %x! Game over!\n", (int) rc);
goto out;
}
// Enumerate all DirectInput mouse(-like) devices:
rc = dinput->EnumDevices(DI8DEVCLASS_POINTER, (LPDIENUMDEVICESCALLBACK) keyboardEnumCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_INCLUDEHIDDEN);
if (DI_OK != rc) {
printf("PsychHID-ERROR: Error return from DirectInput8 EnumDevices(): %x! Game over!\n", (int) rc);
goto out;
}
// Enumerate all DirectInput joystick/gamepad(-like) devices:
rc = dinput->EnumDevices(DI8DEVCLASS_GAMECTRL, (LPDIENUMDEVICESCALLBACK) keyboardEnumCallback, NULL, DIEDFL_ATTACHEDONLY | DIEDFL_INCLUDEHIDDEN);
if (DI_OK != rc) {
printf("PsychHID-ERROR: Error return from DirectInput8 EnumDevices(): %x! Game over!\n", (int) rc);
goto out;
}
// Create keyboard queue mutex for later use:
KbQueueThreadTerminate = FALSE;
PsychInitMutex(&KbQueueMutex);
PsychInitCondition(&KbQueueCondition, NULL);
// Create event object for signalling device state changes:
hEvent = CreateEvent( NULL, // default security attributes
FALSE, // auto-reset event: This would need to be set TRUE for PsychBroadcastCondition() to work on Windows!
FALSE, // initial state is nonsignaled
NULL // no object name
);
// Ready.
return;
out:
ndevices = 0;
// Close our dedicated x-display connection and we are done:
if (dinput) dinput->Release();
dinput = NULL;
PsychErrorExitMsg(PsychError_system, "PsychHID: FATAL ERROR: X Input extension version 2.0 or later not available! Game over!");
//.........这里部分代码省略.........
示例13: IN_InitDInput
qboolean IN_InitDInput(void)
{
HRESULT hResult;
DIPROPDWORD dipdw = {
{
sizeof(DIPROPDWORD), // diph.dwSize
sizeof(DIPROPHEADER), // diph.dwHeaderSize
0, // diph.dwObj
DIPH_DEVICE, // diph.dwHow
}
,
DINPUT_BUFFERSIZE, // dwData
};
#ifdef __GNUC__
hResult = DirectInputCreate(g_wv.hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
#else
hResult = DirectInput8Create(g_wv.hInstance, DIRECTINPUT_VERSION, &IID_IDirectInput8A, &g_pdi, NULL);
#endif
if(FAILED(hResult))
{
#ifdef __GNUC__
Com_Printf("DirectInput8Create failed\n");
#else
Com_Printf("DirectInput8Create failed\n");
#endif
return qfalse;
}
// obtain an interface to the system mouse device.
hResult = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
if(FAILED(hResult))
{
Com_Printf("Couldn't open DI mouse device\n");
return qfalse;
}
// set the data format to "mouse format".
hResult = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
if(FAILED(hResult))
{
Com_Printf("Couldn't set DI mouse format\n");
return qfalse;
}
// set the DirectInput cooperativity level.
hResult = IDirectInputDevice_SetCooperativeLevel(g_pMouse, g_wv.hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
if(FAILED(hResult))
{
Com_Printf("Couldn't set DI coop level\n");
return qfalse;
}
// set the buffer size to DINPUT_BUFFERSIZE elements.
// the buffer size is a DWORD property associated with the device
hResult = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
if(FAILED(hResult))
{
Com_Printf("Couldn't set DI buffersize\n");
return qfalse;
}
return qtrue;
}
示例14: Game_Init
int Game_Init(void *parms, int num_parms)
{
// this function is where you do all the initialization
// for your game
int index; // looping var
char filename[80]; // used to build up files names
// initialize directdraw
DDraw_Init(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP);
#if 0 // directinput7 method
// first create the direct input object
if (DirectInputCreateEx(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput7, (void **)&lpdi,NULL)!=DI_OK)
return(0);
// create a keyboard device //////////////////////////////////
if (lpdi->CreateDeviceEx(GUID_SysKeyboard, IID_IDirectInputDevice7, (void **)&lpdikey, NULL)!=DI_OK)
return(0);
#endif
// first create the direct input object
if (DirectInput8Create(main_instance,DIRECTINPUT_VERSION,IID_IDirectInput8, (void **)&lpdi,NULL)!=DI_OK)
return(0);
// create a 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);
///////////////////////////////////////////////////////////
// load the background
Load_Bitmap_File(&bitmap8bit, "REACTOR.BMP");
// set the palette to background image palette
Set_Palette(bitmap8bit.palette);
// create and load the reactor bitmap image
Create_Bitmap(&reactor, 0,0, 640, 480);
Load_Image_Bitmap(&reactor,&bitmap8bit,0,0,BITMAP_EXTRACT_MODE_ABS);
Unload_Bitmap_File(&bitmap8bit);
// now let's load in all the frames for the skelaton!!!
// create skelaton bob
if (!Create_BOB(&skelaton,0,0,56,72,32,
BOB_ATTR_VISIBLE | BOB_ATTR_MULTI_ANIM,DDSCAPS_SYSTEMMEMORY))
return(0);
// load the frames in 8 directions, 4 frames each
// each set of frames has a walk and a fire, frame sets
// are loaded in counter clockwise order looking down
// from a birds eys view or the x-z plane
for (int direction = 0; direction < 8; direction++)
{
// build up file name
sprintf(filename,"SKELSP%d.BMP",direction);
// load in new bitmap file
Load_Bitmap_File(&bitmap8bit,filename);
Load_Frame_BOB(&skelaton,&bitmap8bit,0+direction*4,0,0,BITMAP_EXTRACT_MODE_CELL);
Load_Frame_BOB(&skelaton,&bitmap8bit,1+direction*4,1,0,BITMAP_EXTRACT_MODE_CELL);
Load_Frame_BOB(&skelaton,&bitmap8bit,2+direction*4,2,0,BITMAP_EXTRACT_MODE_CELL);
Load_Frame_BOB(&skelaton,&bitmap8bit,3+direction*4,0,1,BITMAP_EXTRACT_MODE_CELL);
// unload the bitmap file
Unload_Bitmap_File(&bitmap8bit);
// set the animation sequences for skelaton
Load_Animation_BOB(&skelaton,direction,4,skelaton_anims[direction]);
} // end for direction
// set up stating state of skelaton
Set_Animation_BOB(&skelaton, 0);
Set_Anim_Speed_BOB(&skelaton, 4);
Set_Vel_BOB(&skelaton, 0,0);
Set_Pos_BOB(&skelaton, 0, 128);
// set clipping rectangle to screen extents so mouse cursor
// doens't mess up at edges
//.........这里部分代码省略.........
示例15: DirectInput8Create
bool InputClass::Initialize(HINSTANCE hinstance, HWND hwnd, int screenWidth, int screenHeight)
{
HRESULT result;
//Store the screen size which will be used for positioning the mouse cursor
m_screenHeight = screenWidth;
m_screenHeight = screenHeight;
//initialize the mouse
m_mouseX = 0;
m_mouseY = 0;
//initialize the directInput
result = DirectInput8Create(hinstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_directInput, NULL);
if (FAILED(result))
{
return false;
}
//first initialize the keyboard
result = m_directInput->CreateDevice(GUID_SysKeyboard, &m_keyboard, NULL);
if (FAILED(result))
{
return false;
}
//Set the data format using the predifined format
result = m_keyboard->SetDataFormat(&c_dfDIKeyboard);
if (FAILED(result))
{
return false;
}
//set the keyboard to non-exclusive
result = m_keyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(result))
{
return false;
}
//Aquire the keyboard
result = m_keyboard->Acquire();
if (FAILED(result))
{
return false;
}
//Init the mouse input
result = m_directInput->CreateDevice(GUID_SysMouse, &m_mouse, NULL);
if (FAILED(result))
{
return false;
}
//set the data format for the mouse
result = m_mouse->SetDataFormat(&c_dfDIMouse);
if (FAILED(result))
{
return false;
}
//set the cooperative level of the mouse
result = m_mouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if (FAILED(result))
{
return false;
}
//Acquire the mouse
result = m_mouse->Acquire();
if (FAILED(result))
{
return false;
}
return true;
}