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


C++ LPDIRECTINPUTDEVICE8::QueryInterface方法代码示例

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


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

示例1: Open

bool DIDevice::Open()
{
	m_sName = ConvertACPToUTF8( JoystickInst.tszProductName );

	LOG->Trace( "Opening device '%s'", m_sName.c_str() );
	buffered = true;

	LPDIRECTINPUTDEVICE8 tmpdevice;

	// load joystick
	HRESULT hr = g_dinput->CreateDevice( JoystickInst.guidInstance, &tmpdevice, nullptr );
	if ( hr != DI_OK )
	{
		LOG->Info( hr_format(hr, "OpenDevice: IDirectInput_CreateDevice") );
		return false;
	}
	hr = tmpdevice->QueryInterface( IID_IDirectInputDevice8, (LPVOID *) &Device );
	tmpdevice->Release();
	if ( hr != DI_OK )
	{
		LOG->Info( hr_format(hr, "OpenDevice(%s): IDirectInputDevice::QueryInterface", m_sName.c_str()) );
		return false;
	}

	int coop = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
	if( type == KEYBOARD )
		coop = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;

	hr = Device->SetCooperativeLevel( GraphicsWindow::GetHwnd(), coop );
	if ( hr != DI_OK )
	{
		LOG->Info( hr_format(hr, "OpenDevice(%s): IDirectInputDevice2::SetCooperativeLevel", m_sName.c_str()) );
		return false;
	}

	switch(type)
	{
		case KEYBOARD:
			hr = Device->SetDataFormat( &c_dfDIKeyboard );
			break;
		case JOYSTICK:
			hr = Device->SetDataFormat( &c_dfDIJoystick );
			break;
		case MOUSE:
			hr = Device->SetDataFormat( &c_dfDIMouse );
			break;
	}
	if ( hr != DI_OK )
	{
		LOG->Info( hr_format(hr, "OpenDevice(%s): IDirectInputDevice2::SetDataFormat", m_sName.c_str()) );
		return false;
	}

	switch( type )
	{
		case JOYSTICK:
			Device->EnumObjects( DIJoystick_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_POV);
			break;
		case KEYBOARD:
			// Always 256-button.
			for( int b = 0; b < 256; ++b )
			{
				input_t in;
				in.type = in.KEY;

				in.num = ConvertScancodeToKey(b);
				in.ofs = b;
				buttons++;
				Inputs.push_back(in);
			}
			break;
		case MOUSE:
			Device->EnumObjects( DIMouse_EnumDevObjectsProc, this, DIDFT_BUTTON | DIDFT_AXIS | DIDFT_ANYINSTANCE );
			break;
	}

	{
		DIPROPDWORD dipdw;
		memset(&dipdw, 0, sizeof(dipdw));
		dipdw.diph.dwSize = sizeof(dipdw);
		dipdw.diph.dwHeaderSize = sizeof(dipdw.diph);
		dipdw.diph.dwObj = 0;
		dipdw.diph.dwHow = DIPH_DEVICE;
		dipdw.dwData = INPUT_QSIZE;
		hr = Device->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph );
		if ( hr == DI_POLLEDDEVICE )
		{
			/* This device doesn't support buffering, so we're forced
			 * to use less reliable polling. */
			buffered = false;
		}
		else if ( hr != DI_OK )
		{
			LOG->Info( hr_format(hr, "OpenDevice(%s): IDirectInputDevice2::SetProperty", m_sName.c_str()) );
			return false;
		}
	}

	return true;
}
开发者ID:dguzek,项目名称:stepmania,代码行数:100,代码来源:InputHandler_DirectInputHelper.cpp

示例2: QueryInterface

 /*** IUnknown methods ***/
 HRESULT _stdcall QueryInterface (REFIID riid, LPVOID * ppvObj) {
     return RealDevice->QueryInterface(riid,ppvObj);
 }
开发者ID:europop,项目名称:morrgraphext,代码行数:4,代码来源:DInput+(mouse+combat).cpp


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