当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECTINPUT8类代码示例

本文整理汇总了C++中LPDIRECTINPUT8的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUT8类的具体用法?C++ LPDIRECTINPUT8怎么用?C++ LPDIRECTINPUT8使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LPDIRECTINPUT8类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: 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; 
}
开发者ID:Noxalus,项目名称:TP3D3,代码行数:65,代码来源:InputDevice.cpp

示例2: EnumJoysticksCallback

BOOL CALLBACK DirectInputRegistry::EnumJoysticksCallback( const DIDEVICEINSTANCE* didInstance, VOID* )
{
    HRESULT hr;
    LPDIRECTINPUT8 device = DirectInputRegistry::instance()->getDevice();
    if ( device )
    {
        hr = device->CreateDevice( didInstance->guidInstance,
                                   &(DirectInputRegistry::instance()->getJoyStick()), NULL );
    }
    if ( FAILED(hr) ) return DIENUM_CONTINUE;
    return DIENUM_STOP;
}
开发者ID:151706061,项目名称:OpenSceneGraph,代码行数:12,代码来源:DirectInputRegistry.cpp

示例3: D3DXCreateTextureFromFile

void MOUSE::InitMouse(IDirect3DDevice9* Dev, HWND wnd)
{
	try
	{
		m_pDevice = Dev;

		//Load texture and init sprite
		D3DXCreateTextureFromFile(m_pDevice, "cursor/cursor.dds", &m_pMouseTexture);
		D3DXCreateSprite(m_pDevice, &m_pSprite);

		//Get directinput object
		LPDIRECTINPUT8 directInput = NULL;

		DirectInput8Create(GetModuleHandle(NULL),	// Retrieves the application handle
						   0x0800,					// v.8.0	
						   IID_IDirectInput8,		// Interface ID
						   (VOID**)&directInput,	// Our DirectInput Object
						   NULL);

		//Acquire Default System mouse
		directInput->CreateDevice(GUID_SysMouse, &m_pMouseDevice, NULL);		
		m_pMouseDevice->SetDataFormat(&c_dfDIMouse);
		m_pMouseDevice->SetCooperativeLevel(wnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
		m_pMouseDevice->Acquire();	        

		//Get viewport size and init mouse location
		D3DVIEWPORT9 v;
		m_pDevice->GetViewport(&v);
		m_viewport.left = v.X;
		m_viewport.top = v.Y;
		m_viewport.right = v.X + v.Width;
		m_viewport.bottom = v.Y + v.Height;

		x = v.X + v.Width / 2;
		y = v.Y + v.Height / 2;

		//Release Direct Input Object
		directInput->Release();

		//Create Mouse Sphere
		D3DXCreateSphere(m_pDevice, 0.2f, 5, 5, &m_pSphereMesh, NULL);

		//Create Ball Material
		m_ballMtrl.Diffuse = D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f);
		m_ballMtrl.Specular = m_ballMtrl.Ambient = m_ballMtrl.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	}
	catch(...)
	{
		debug.Print("Error in MOUSE::InitMouse()");
	}	
}
开发者ID:Alriightyman,项目名称:RTS,代码行数:51,代码来源:mouse.cpp

示例4: initialize

		void initialize(HWND hwnd_) {


			// DirectInputの作成
			LPDIRECTINPUT8 keyboard = NULL;
			HRESULT hr = DirectInput8Create(::GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&keyboard, NULL); 
			if (FAILED(hr)) {
				debug_out::trace("DirectInputオブジェクトの生成に失敗しました。");
				throw nyx::com_exception("DirectInputオブジェクトの生成に失敗しました。", hr);
			}

			// デバイス・オブジェクトを作成
			LPDIRECTINPUTDEVICE8 keyboardDevice = NULL;
			hr = keyboard->CreateDevice(GUID_SysKeyboard, &keyboardDevice, NULL); 
			if (FAILED(hr)) {
				debug_out::trace("DirectInputDeviceオブジェクトの生成に失敗しました。");
				throw nyx::com_exception("DirectInputDeviceオブジェクトの生成に失敗しました。", hr);
			}


			// データ形式を設定
			hr = keyboardDevice->SetDataFormat(&c_dfDIKeyboard);
			if (FAILED(hr)) {
				debug_out::trace("データ形式の設定に失敗しました。");
				throw nyx::com_exception("データ形式の設定に失敗しました。", hr);
			}
			//モードを設定(フォアグラウンド&非排他モード)
			hr = keyboardDevice->SetCooperativeLevel(hwnd_, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
			if (FAILED(hr)) {
				debug_out::trace("制御モードの設定に失敗しました。");
				throw nyx::com_exception("制御モードの設定に失敗しました。", hr);
			}
			// バッファリング・データを取得するため、バッファ・サイズを設定
			DIPROPDWORD diprop = {};
			diprop.diph.dwSize	= sizeof(diprop); 
			diprop.diph.dwHeaderSize	= sizeof(diprop.diph); 
			diprop.diph.dwObj	= 0;
			diprop.diph.dwHow	= DIPH_DEVICE;
			diprop.dwData = 255;
			hr = keyboardDevice->SetProperty(DIPROP_BUFFERSIZE, &diprop.diph);
			if (FAILED(hr)) {
				debug_out::trace("バッファサイズの設定に失敗しました。");
				throw nyx::com_exception("バッファサイズの設定に失敗しました。", hr);
			}


			keyboard_ = DirectInputPtr(keyboard, false);
			keyboardDevice_ = DirectInputDevicePtr(keyboardDevice, false);

			isInitialized = true;
		}
开发者ID:thayamizu,项目名称:Nyx,代码行数:51,代码来源:Keyboard.cpp

示例5: 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;
}
开发者ID:AT13ANo5,项目名称:GLProject,代码行数:37,代码来源:Keyboard.cpp

示例6: sizeof

	// コンストラクタ
	Mouse::Mouse(LPDIRECTINPUT8 dInput, HWND hWnd)
	{
		if (FAILED(dInput->CreateDevice(GUID_SysMouse, &dmouse, nullptr)))
		{
			return;
		}

		if (FAILED(dmouse->SetDataFormat(&c_dfDIMouse2)))
		{
			return;
		}

		if (FAILED(dmouse->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
		{
			return;
		}

		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_ABS;

		if (FAILED(dmouse->SetProperty(DIPROP_AXISMODE, &diprop.diph)))
		{
			return;
		}
	}
开发者ID:Naoki-Nakagawa,项目名称:PuniPuni,代码行数:30,代码来源:Input.cpp

示例7: 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;
}
开发者ID:kyphelps,项目名称:spring-2013,代码行数:25,代码来源:MyDirectX.cpp

示例8: 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;
}
开发者ID:SeungMinChoi,项目名称:ejcharpenay,代码行数:28,代码来源:graphics.cpp

示例9: 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;
}
开发者ID:chenbk85,项目名称:3dlearn,代码行数:55,代码来源:GutInput.cpp

示例10: main

int main()
{
    HRESULT hr;

    hr=DirectInput8Create
       (GetModuleHandle (NULL), DIRECTINPUT_VERSION, IID_IDirectInput8A,
       (VOID**)&gp_DI, NULL);

    printf("Devices\n-----------------\n");
    hr = gp_DI->EnumDevices(DI8DEVCLASS_ALL,EnumDevicesCallback, NULL, DIEDFL_ALLDEVICES);


    memset(&g_ActionFormat, 0, sizeof(g_ActionFormat));
    g_ActionFormat.dwSize = sizeof(g_ActionFormat);
    g_ActionFormat.dwActionSize = sizeof(DIACTION);
    g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_space);
    g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
    g_ActionFormat.rgoAction = g_commands_space;
    g_ActionFormat.guidActionMap = ACTIONMAP_GUID;
    g_ActionFormat.dwBufferSize = 32;
    g_ActionFormat.dwGenre = DIVIRTUAL_SPACESIM;

    printf("Space combat enumeration\n------------\n");
    hr=gp_DI->EnumDevicesBySemantics
       (NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES );

//    if(FAILED(hr)) printf("Failed?\n");

//    g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_driving);
//    g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
//    g_ActionFormat.rgoAction = g_commands_driving;
//    g_ActionFormat.dwGenre = DIVIRTUAL_DRIVING_RACE;

//    printf("Driving race enumeration\n------------\n");
//    hr=gp_DI->EnumDevicesBySemantics
//       (NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES);

//    if(FAILED(hr)) printf("Failed?\n");

//    g_ActionFormat.dwNumActions = ARRAYSIZE(g_commands_fps);
//    g_ActionFormat.dwDataSize = 4 * g_ActionFormat.dwNumActions;
//    g_ActionFormat.rgoAction = g_commands_fps;
//    g_ActionFormat.dwGenre = DIVIRTUAL_FIGHTING_FPS;

//    printf("First person shooter enumeration\n------------\n");
//    hr=gp_DI->EnumDevicesBySemantics
//       (NULL, &g_ActionFormat, EnumSemanticsCallback, NULL, DIEDBSFL_AVAILABLEDEVICES);

//    if(FAILED(hr)) printf("Failed?\n");

    return 0;
}
开发者ID:lfzawacki,项目名称:dinput-samples,代码行数:52,代码来源:devices_test.cpp

示例11: 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;
}
开发者ID:DrivenByHim,项目名称:BeginningGameProgramming,代码行数:15,代码来源:dxinput.cpp

示例12: 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;
}
开发者ID:guorenxu,项目名称:GreatYourOwnGatsby,代码行数:15,代码来源:DXInput.cpp

示例13: 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;		// 列挙を続ける
}
开发者ID:minamiliu,项目名称:Time_To_Shoot,代码行数:28,代码来源:input.cpp

示例14: disposeDirectInput

void disposeDirectInput()
{
    logg( "    Disposing Keyboard...", false );
    dinKeyboard->Unacquire();    // make sure the keyboard is unacquired
    dinKeyboard = NULL;
    logg( " Successfully disposed Keyboard." );
    
    logg( "    Disposing Joysticks...", false );
    for ( int i = numJoysticks - 1; i >= 0; i-- )
    {
        try
        {
            dinJoysticks[i]->Unacquire();
            dinJoysticks[i]->Release();
        }
        catch ( ... )
        {
            loggui( " WARNING: Caught an exception while trying to dispose Joystick ", i );
        }
        
        dinJoysticks[i] = NULL;
    }
    logg( " Successfully disposed Joysticks." );
    
    logg( "    Disposing DirectInput...", false );
    din->Release();    // close DirectInput before exiting
    din = NULL;
    logg( " Successfully disposed DirectInput." );
}
开发者ID:CSharles,项目名称:rfDynHUD,代码行数:29,代码来源:direct_input.cpp

示例15: Game_Shutdown

int Game_Shutdown(void *parms,  int num_parms)
{
// this function is where you shutdown your game and
// release all resources that you allocated

// kill the bug blaster
Destroy_BOB(&blaster);

// kill the mushroom maker
for (int index=0; index<4; index++)
    Destroy_Bitmap(&mushrooms[index]);

// kill the playfield bitmap
Destroy_Bitmap(&playfield);

// release joystick
lpdijoy->Unacquire();
lpdijoy->Release();
lpdi->Release();

// shutdonw directdraw
DDraw_Shutdown();

// return success
return(1);
} // end Game_Shutdown
开发者ID:calyx,项目名称:windows-game-source-code,代码行数:26,代码来源:demo9_4_16b.cpp


注:本文中的LPDIRECTINPUT8类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。