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


C++ LPDIRECTINPUTDEVICE::SetDataFormat方法代码示例

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


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

示例1: PisteInput_Alusta_Mouse

bool PisteInput_Alusta_Mouse()
{
	
	if (FAILED(PI_lpdi->CreateDevice(GUID_SysMouse, &PI_lpdimouse, NULL))) {
		PisteLog_Kirjoita("[Warning] Piste Input: No mouse available! \n");
		PI_mouse_available = false;
	}

	if (PI_mouse_available)
	{
		if (FAILED(PI_lpdimouse->SetCooperativeLevel(PI_main_window_handle,
			DISCL_BACKGROUND | DISCL_NONEXCLUSIVE))) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Set cooperative level failed! \n");
			PI_mouse_available = false;
		}

		if (FAILED(PI_lpdimouse->SetDataFormat(&c_dfDIMouse))) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Set data format failed! \n");
			PI_mouse_available = false;
		}

		if (FAILED(PI_lpdimouse->Acquire())) {
			PisteLog_Kirjoita("[Error] Piste Input: Mouse - Acquire failed! \n");
			PI_mouse_available = false;
		}
	}

	return PI_mouse_available;
}
开发者ID:stt,项目名称:pk2,代码行数:29,代码来源:PisteInput.cpp

示例2: PisteInput_Alusta_Keyboard

bool PisteInput_Alusta_Keyboard()
{
	
	if (FAILED(PI_lpdi->CreateDevice(GUID_SysKeyboard, &PI_lpdikey, NULL))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Create Device failed! \n");
		return false;
	}
	
	if (FAILED(PI_lpdikey->SetCooperativeLevel(PI_main_window_handle, 
		DISCL_BACKGROUND | DISCL_NONEXCLUSIVE /* | DISCL_FOREGROUND*/))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Set cooperative level failed! \n");
		return false;
	}

	if (FAILED(PI_lpdikey->SetDataFormat(&c_dfDIKeyboard))) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Set data format failed! \n");
		return false;
	}

	if (FAILED(PI_lpdikey->Acquire())) {
		PisteLog_Kirjoita("[Error] Piste Input: Keyboard - Acquire failed! \n");
		return false;
	}

	return true;
}
开发者ID:stt,项目名称:pk2,代码行数:26,代码来源:PisteInput.cpp

示例3: initDirectInput

bool DXGame::initDirectInput(HINSTANCE hInstance){
	dprintf(("Entered initDirectInput\n"));
	if(FAILED(DirectInputCreate(hInstance, DIRECTINPUT_VERSION, &lpDirectInput, NULL))){
		dprintf(("*****COULD NOT CREATE DIRECT INPUT OBJECT*****\n"));
	}
	if(FAILED(lpDirectInput->CreateDevice(GUID_SysKeyboard, &lpKeyboard, NULL))){
		dprintf(("*****COULD NOT CREATE KEYBOARD*****\n"));
	}

	// set cooperation level
	if (lpKeyboard->SetCooperativeLevel(hwnd, 
		DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK){
		dprintf(("COULD NOT SetCooperative Level\n"));
		return false;
	}
		

	// set data format
	if (lpKeyboard->SetDataFormat(&c_dfDIKeyboard)!=DI_OK){
		dprintf(("COULD NOT Set Data Format\n"));
		return false;
	}
	

	// acquire the keyboard
	if (lpKeyboard->Acquire()!=DI_OK){
		dprintf(("COULD NOT Acquire the keyboard\n"));
		return false;
	}
	
	dprintf(("Leaving the DirectInput\n"));

	return true;
}
开发者ID:brettatoms,项目名称:robopanic,代码行数:34,代码来源:DXGame.cpp

示例4: InitialiseDirectMouse

BOOL InitialiseDirectMouse()

{
    GUID    guid = GUID_SysMouse;
	HRESULT hres;

	//MouseButton = 0;
    
    // Obtain an interface to the system mouse device.
    hres = lpdi->CreateDevice(guid, &lpdiMouse, NULL);
	if (hres != DI_OK) return FALSE;

    // Set the data format to "mouse format".
    hres = lpdiMouse->SetDataFormat(&c_dfDIMouse);
    if (hres != DI_OK) return FALSE;
	
    //  Set the cooperativity level.

    #if debug
	// This level should allow the debugger to actually work
	// not to mention drop 'n' drag in sub-window mode
    hres = lpdiMouse->SetCooperativeLevel(hWndMain,
                       DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
	#else
	// this level is the most likely to work across
	// multiple mouse drivers
    hres = lpdiMouse->SetCooperativeLevel(hWndMain,
                       DISCL_EXCLUSIVE | DISCL_FOREGROUND);
	#endif
    if (hres != DI_OK) return FALSE;

    //  Set the buffer size for reading the mouse to
	//  DMouse_BufferSize elements
    //  mouse-type should be relative by default, so there
	//  is no need to change axis mode.
    DIPROPDWORD dipdw =
    {
        {
            sizeof(DIPROPDWORD),        // diph.dwSize
            sizeof(DIPROPHEADER),       // diph.dwHeaderSize
            0,                          // diph.dwObj
            DIPH_DEVICE,                // diph.dwHow
        },
        DMouse_BufferSize,              // dwData
    };

    hres = lpdiMouse->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph);

    if (hres != DI_OK) return FALSE;

    // try to acquire the mouse
    hres = lpdiMouse->Acquire();
	
	return TRUE;
}
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:55,代码来源:Di_func.cpp

示例5: InitKeyboard

bool InitKeyboard ()
{
    HRESULT hr;
    if (FAILED(hr = pdi->CreateDevice(GUID_SysKeyboard, &pdiKeyboard, NULL)))
        TRACE("!!! Failed to create keyboard device (%#08lx)\n", hr);
    else if (FAILED(hr = pdiKeyboard->SetCooperativeLevel(g_hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
        TRACE("!!! Failed to set cooperative level of keyboard device (%#08lx)\n", hr);
    else if (FAILED(hr = pdiKeyboard->SetDataFormat(&c_dfDIKeyboard)))
        TRACE("!!! Failed to set data format of keyboard device (%#08lx)\n", hr);
    else
    {
        DIPROPDWORD dipdw = { { sizeof(DIPROPDWORD), sizeof(DIPROPHEADER), 0, DIPH_DEVICE, }, EVENT_BUFFER_SIZE, };

        if (FAILED(hr = pdiKeyboard->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)))
            TRACE("!!! Failed to set keyboard buffer size\n", hr);

        return true;
    }

    return false;
}
开发者ID:DavidKnight247,项目名称:simcoupe,代码行数:21,代码来源:Input.cpp

示例6: InitialiseDirectKeyboard

BOOL InitialiseDirectKeyboard()

{    
    HRESULT  hRes;

    // try to create keyboard device
    if (lpdi->CreateDevice(guid, &lpdiKeyboard, NULL) !=DI_OK)
      {
	   #if debug
	   ReleaseDirect3D();
	   exit(0x4112);
	   #else
	   return FALSE;
	   #endif
      }

    // Tell DirectInput that we want to receive data in keyboard format
    if (lpdiKeyboard->SetDataFormat(&c_dfDIKeyboard) != DI_OK)
      {
	   #if debug
	   ReleaseDirect3D();
	   exit(0x4113);
	   #else
	   return FALSE;
	   #endif
      }

    // set cooperative level
	// this level is the most likely to work across
	// multiple hardware targets
	// (i.e. this is probably best for a production
	// release)
	#if UseForegroundKeyboard
    if (lpdiKeyboard->SetCooperativeLevel(hWndMain,
                         DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK)
	#else
	// this level makes alt-tabbing multiple instances in
	// SunWindow mode possible without receiving lots
	// of false inputs
    if (lpdiKeyboard->SetCooperativeLevel(hWndMain,
                         DISCL_NONEXCLUSIVE | DISCL_BACKGROUND) != DI_OK)
	#endif
      {
	   #if debug
	   ReleaseDirect3D();
	   exit(0x4114);
	   #else
	   return FALSE;
	   #endif
      }

    // try to acquire the keyboard
    hRes = lpdiKeyboard->Acquire();
    if (hRes == DI_OK)
      {
       // keyboard was acquired
       DIKeyboardOkay = TRUE;
      }
    else
      {
       // keyboard was NOT acquired
       DIKeyboardOkay = FALSE;
      }

    // if we get here, all objects were created successfully
    return TRUE;    
}
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:67,代码来源:Di_func.cpp

示例7: di_init

int di_init()
{
    HRESULT hr;

	 return 0;


    /*
     *  Register with the DirectInput subsystem and get a pointer
     *  to a IDirectInput interface we can use.
     *
     *  Parameters:
     *
     *      g_hinst
     *
     *          Instance handle to our application or DLL.
     *
     *      DIRECTINPUT_VERSION
     *
     *          The version of DirectInput we were designed for.
     *          We take the value from the <dinput.h> header file.
     *
     *      &g_pdi
     *
     *          Receives pointer to the IDirectInput interface
     *          that was created.
     *
     *      NULL
     *
     *          We do not use OLE aggregation, so this parameter
     *          must be NULL.
     *
     */
    hr = DirectInputCreate(GetModuleHandle(NULL), 0x300, &Di_object, NULL);

    if (FAILED(hr)) {
        mprintf(( "DirectInputCreate failed!\n" ));
        return FALSE;
    }

    /*
     *  Obtain an interface to the system keyboard device.
     *
     *  Parameters:
     *
     *      GUID_SysKeyboard
     *
     *          The instance GUID for the device we wish to access.
     *          GUID_SysKeyboard is a predefined instance GUID that
     *          always refers to the system keyboard device.
     *
     *      &g_pKeyboard
     *
     *          Receives pointer to the IDirectInputDevice interface
     *          that was created.
     *
     *      NULL
     *
     *          We do not use OLE aggregation, so this parameter
     *          must be NULL.
     *
     */
    hr = Di_object->CreateDevice(GUID_SysKeyboard, &Di_keyboard, NULL);

    if (FAILED(hr)) {
        mprintf(( "CreateDevice failed!\n" ));
        return FALSE;
    }

    /*
     *  Set the data format to "keyboard format".
     *
     *  A data format specifies which controls on a device we
     *  are interested in, and how they should be reported.
     *
     *  This tells DirectInput that we will be passing an array
     *  of 256 bytes to IDirectInputDevice::GetDeviceState.
     *
     *  Parameters:
     *
     *      c_dfDIKeyboard
     *
     *          Predefined data format which describes
     *          an array of 256 bytes, one per scancode.
     */
    hr = Di_keyboard->SetDataFormat(&c_dfDIKeyboard);

    if (FAILED(hr)) {
        mprintf(( "SetDataFormat failed!\n" ));
        return FALSE;
    }


    /*
     *  Set the cooperativity level to let DirectInput know how
     *  this device should interact with the system and with other
     *  DirectInput applications.
     *
     *  Parameters:
     *
//.........这里部分代码省略.........
开发者ID:Admiral-MS,项目名称:fs2open.github.com,代码行数:101,代码来源:key.cpp

示例8: di_init

int di_init()
{
	HRESULT hr;

	if (Mouse_mode == MOUSE_MODE_WIN){
		return 0;
	}

	Di_mouse_inited = 0;
	hr = DirectInputCreate(GetModuleHandle(NULL), DIRECTINPUT_VERSION, &Di_mouse_obj, NULL);
	if (FAILED(hr)) {
		hr = DirectInputCreate(GetModuleHandle(NULL), 0x300, &Di_mouse_obj, NULL);
		if (FAILED(hr)) {
			mprintf(( "DirectInputCreate() failed!\n" ));
			return FALSE;
		}
	}

	hr = Di_mouse_obj->CreateDevice(GUID_SysMouse, &Di_mouse, NULL);
	if (FAILED(hr)) {
		mprintf(( "CreateDevice() failed!\n" ));
		return FALSE;
	}

	hr = Di_mouse->SetDataFormat(&c_dfDIMouse);
	if (FAILED(hr)) {
		mprintf(( "SetDataFormat() failed!\n" ));
		return FALSE;
	}

	hr = Di_mouse->SetCooperativeLevel((HWND)os_get_window(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
	if (FAILED(hr)) {
		mprintf(( "SetCooperativeLevel() failed!\n" ));
		return FALSE;
	}
/*
	DIPROPDWORD hdr;

	// Turn on buffering
	hdr.diph.dwSize = sizeof(DIPROPDWORD); 
	hdr.diph.dwHeaderSize = sizeof(DIPROPHEADER);
	hdr.diph.dwObj = 0;		
	hdr.diph.dwHow = DIPH_DEVICE;	// Apply to entire device
	hdr.dwData = 16;	//MAX_BUFFERED_KEYBOARD_EVENTS;

	hr = Di_mouse->SetProperty( DIPROP_BUFFERSIZE, &hdr.diph );
	if (FAILED(hr)) {
		mprintf(( "SetProperty DIPROP_BUFFERSIZE failed\n" ));
		return FALSE;
	}

	Di_event = CreateEvent( NULL, FALSE, FALSE, NULL );
	Assert(Di_event != NULL);

	hr = Di_mouse->SetEventNotification(Di_event);
	if (FAILED(hr)) {
		mprintf(( "SetEventNotification failed\n" ));
		return FALSE;
	}
*/
	Di_mouse->Acquire();

	Di_mouse_inited = 1;
	return TRUE;
}
开发者ID:Admiral-MS,项目名称:fs2open.github.com,代码行数:65,代码来源:mouse.cpp

示例9: input_dinput_init

/**
 * input_dinput_init(): Initialize the DirectInput subsystem.
 * @return 0 on success; non-zero on error.
 */
int input_dinput_init(void)
{
	int i;
	HRESULT rval;
	
	// Attempt to initialize DirectInput 5.
	input_dinput_version = 0;
	rval = DirectInputCreate(ghInstance, DIRECTINPUT_VERSION_5, &lpDI, NULL);
	if (rval == DI_OK)
	{
		// DirectInput 5 initialized.
		LOG_MSG(input, LOG_MSG_LEVEL_INFO,
			"Initialized DirectInput 5.");
		input_dinput_version = DIRECTINPUT_VERSION_5;
	}
	else
	{
		// Attempt to initialize DirectInput 3.
		rval = DirectInputCreate(ghInstance, DIRECTINPUT_VERSION_3, &lpDI, NULL);
		if (rval == DI_OK)
		{
			// DirectInput 3 initialized.
			LOG_MSG(input, LOG_MSG_LEVEL_INFO,
				"Initialized DirectInput 3.");
			input_dinput_version = DIRECTINPUT_VERSION_3;
		}
		else
		{
			// DirectInput could not be initialized.
			LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
				"Could not initialize DirectInput 3 or DirectInput 5.\n\nYou must have DirectX 3 or later.");
			return -1;
		}
	}
	
	input_dinput_joystick_initialized = false;
	input_dinput_joystick_error = false;
	input_dinput_num_joysticks = 0;
	memset(input_dinput_joy_id, 0x00, sizeof(input_dinput_joy_id));
	
	//rval = lpDI->CreateDevice(GUID_SysMouse, &lpDIDMouse, NULL);
	lpDIDMouse = NULL;
	rval = lpDI->CreateDevice(GUID_SysKeyboard, &lpDIDKeyboard, NULL);
	if (rval != DI_OK)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
			"lpDI->CreateDevice() failed. (Keyboard)");
		
		// TODO: Use cross-platform error numbers, not just DirectInput return values.
		return -2;
	}
	
	// Set the cooperative level.
	input_dinput_set_cooperative_level(NULL);
	
	//rval = lpDIDMouse->SetDataFormat(&c_dfDIMouse);
	rval = lpDIDKeyboard->SetDataFormat(&c_dfDIKeyboard);
	if (rval != DI_OK)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_CRITICAL,
			"lpDIDKeyboard->SetDataFormat() failed.");
		
		// TODO: Use cross-platform error numbers, not just DirectInput return values.
		return -1;
	}
	
	//rval = lpDIDMouse->Acquire();
	for(i = 0; i < 10; i++)
	{
		rval = lpDIDKeyboard->Acquire();
		if (rval == DI_OK)
			break;
		GensUI::sleep(10);
	}
	
	// Clear the DirectInput arrays.
	memset(input_dinput_keys, 0x00, sizeof(input_dinput_keys));
	memset(input_dinput_joy_id, 0x00, sizeof(input_dinput_joy_id));
	memset(input_dinput_joy_state, 0x00, sizeof(input_dinput_joy_state));
	
	// DirectInput initialized.
	return 0;
}
开发者ID:salviati,项目名称:gens-gs-debug,代码行数:87,代码来源:input_dinput.cpp


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