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


C++ LPDIRECTINPUTDEVICE类代码示例

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


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

示例1: EnumJoystickProc

BOOL CALLBACK EnumJoystickProc (LPCDIDEVICEINSTANCE pdiDevice_, LPVOID lpv_)
{
    HRESULT hr;

    LPDIRECTINPUTDEVICE pdiJoystick;
    if (FAILED(hr = pdi->CreateDevice(pdiDevice_->guidInstance, &pdiJoystick, NULL)))
        TRACE("!!! Failed to create joystick device (%#08lx)\n", hr);
    else
    {
        DIDEVICEINSTANCE didi = { sizeof(didi) };
        strcpy(didi.tszInstanceName, "<unknown>");  // WINE fix for missing implementation

        if (FAILED(hr = pdiJoystick->GetDeviceInfo(&didi)))
            TRACE("!!! Failed to get joystick device info (%#08lx)\n", hr);

        // Overloaded use - if custom data was supplied, it's a combo box ID to add the string to
        else if (lpv_)
            SendMessage(reinterpret_cast<HWND>(lpv_), CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(didi.tszInstanceName));
        else
        {
            IDirectInputDevice2* pDevice;

            // We need an IDirectInputDevice2 interface for polling, so query for it
            if (FAILED(hr = pdiJoystick->QueryInterface(IID_IDirectInputDevice2, reinterpret_cast<void **>(&pDevice))))
                TRACE("!!! Failed to query joystick for IID_IDirectInputDevice2 (%#08lx)\n", hr);

            // If the device name matches the joystick 1 device name, save a pointer to it
            else if (!lstrcmpi(didi.tszInstanceName, GetOption(joydev1)))
                pdidJoystick1 = pDevice;

            // If the device name matches the joystick 2 device name, save a pointer to it
            else if (!lstrcmpi(didi.tszInstanceName, GetOption(joydev2)))
                pdidJoystick2 = pDevice;

            // No match
            else
                pDevice->Release();

            pdiJoystick->Release();
        }
    }

    // Continue looking for other devices, even tho we failed with the current one
    return DIENUM_CONTINUE;
}
开发者ID:DavidKnight247,项目名称:simcoupe,代码行数:45,代码来源:Input.cpp

示例2: EnumJoysticksCallback

//-----------------------------------------------------------------------------
// Function: EnumJoysticksCallback
//
// Description: 
//      Called once for each enumerated joystick. If we find one, 
//       create a device interface on it so we can play with it.
//
//-----------------------------------------------------------------------------
BOOL CALLBACK EnumJoysticksCallback( LPCDIDEVICEINSTANCE pInst, 
                                     LPVOID lpvContext )
{
    HRESULT             hr;
    LPDIRECTINPUTDEVICE pDevice;

    // obtain an interface to the enumerated force feedback joystick.
    hr = lpdi->CreateDevice( pInst->guidInstance, &pDevice, NULL );

    // if it failed, then we can't use this joystick for some
    // bizarre reason.  (Maybe the user unplugged it while we
    // were in the middle of enumerating it.)  So continue enumerating
    if ( FAILED(hr) ) 
        return DIENUM_CONTINUE;

    // we successfully created an IDirectInputDevice.  So stop looking 
    // for another one.
    g_pJoystick = pDevice;

    // query for IDirectInputDevice2 - we need this to poll the joystick 
    pDevice->QueryInterface( IID_IDirectInputDevice2, (LPVOID *)&g_pJoystickDevice2 );

    return DIENUM_STOP;
}
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:32,代码来源:Di_func.cpp

示例3: 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

示例4: 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

示例5: 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

示例6: di_cleanup

void di_cleanup()
{
    /*
     *  Destroy any lingering IDirectInputDevice object.
     */
    if (Di_keyboard) {

        /*
         *  Cleanliness is next to godliness.  Unacquire the device
         *  one last time just in case we got really confused and tried
         *  to exit while the device is still acquired.
         */
        Di_keyboard->Unacquire();

        Di_keyboard->Release();
        Di_keyboard = NULL;
    }

    /*
     *  Destroy any lingering IDirectInput object.
     */
    if (Di_object) {
        Di_object->Release();
        Di_object = NULL;
    }

	if ( Di_event )	{
		CloseHandle(Di_event);
		Di_event = NULL;
	}

}
开发者ID:Admiral-MS,项目名称:fs2open.github.com,代码行数:32,代码来源:key.cpp

示例7: mouse_eval_deltas_di

void mouse_eval_deltas_di()
{
	int repeat = 1;
	HRESULT hr = 0;
	DIMOUSESTATE mouse_state;

	Mouse_dx = Mouse_dy = Mouse_dz = 0;
	if (!Di_mouse_inited)
		return;

	repeat = 1;
	memset(&mouse_state, 0, sizeof(mouse_state));
	while (repeat) {
		repeat = 0;

		hr = Di_mouse->GetDeviceState(sizeof(mouse_state), &mouse_state);
		if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) {
			// DirectInput is telling us that the input stream has
			// been interrupted.  We aren't tracking any state
			// between polls, so we don't have any special reset
			// that needs to be done.  We just re-acquire and
			// try again.
			Sleep(500);		// Pause a half second...
			hr = Di_mouse->Acquire();
			if (SUCCEEDED(hr))
				repeat = 1;
		}
	}

	if (SUCCEEDED(hr)) {
		Mouse_dx = (int) mouse_state.lX;
		Mouse_dy = (int) mouse_state.lY;
		Mouse_dz = (int) mouse_state.lZ;

	} else {
		Mouse_dx = Mouse_dy = Mouse_dz = 0;
	}

	Mouse_x += Mouse_dx;
	Mouse_y += Mouse_dy;

	if (Mouse_x < 0)
		Mouse_x = 0;

	if (Mouse_y < 0)
		Mouse_y = 0;

	if (Mouse_x >= gr_screen.max_w)
   		Mouse_x = gr_screen.max_w - 1;

	if (Mouse_y >= gr_screen.max_h)
  		Mouse_y = gr_screen.max_h - 1;

	// keep the mouse inside our window so we don't switch applications or anything (debug bug people reported?)
	// JH: Dang!  This makes the mouse readings in DirectInput act screwy!
//	mouse_force_pos(gr_screen.max_w / 2, gr_screen.max_h / 2);
}
开发者ID:chief1983,项目名称:Imperial-Alliance,代码行数:57,代码来源:MOUSE.CPP

示例8: 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

示例9: Exit

void Input::Exit (bool fReInit_/*=false*/)
{
    TRACE("Input::Exit(%d)\n", fReInit_);

    if (pdiKeyboard) { pdiKeyboard->Unacquire(); pdiKeyboard->Release(); pdiKeyboard = NULL; }
    if (pdidJoystick1) { pdidJoystick1->Unacquire(); pdidJoystick1->Release(); pdidJoystick1 = NULL; }
    if (pdidJoystick2) { pdidJoystick2->Unacquire(); pdidJoystick2->Release(); pdidJoystick2 = NULL; }
    if (pdi) { pdi->Release(); pdi = NULL; }

    Keyboard::Exit(fReInit_);
}
开发者ID:DavidKnight247,项目名称:simcoupe,代码行数:11,代码来源:Input.cpp

示例10: Purge

void Input::Purge ()
{
    // Purge queued keyboard items
    if (pdiKeyboard && SUCCEEDED(pdiKeyboard->Acquire()))
    {
        DWORD dwItems = ULONG_MAX;
        if (SUCCEEDED(pdiKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA), NULL, &dwItems, 0)) && dwItems)
            TRACE("%lu keyboard items purged\n", dwItems);
    }

    Keyboard::Purge();
}
开发者ID:DavidKnight247,项目名称:simcoupe,代码行数:12,代码来源:Input.cpp

示例11: release

void DXGame::release(){
	if(lpDirectDrawObject != NULL){		//if DD object exists
		if(lpPrimary != NULL)				//if primary surface exists
			lpPrimary->Release();			//release primary surface
		lpDirectDrawObject->Release();	//release DD object
	}	
	if(lpDirectInput != NULL){
		if(lpKeyboard){
			lpKeyboard->Unacquire();
			lpKeyboard->Release();
		} 
		lpDirectInput->Release();
	}
}
开发者ID:brettatoms,项目名称:robopanic,代码行数:14,代码来源:DXGame.cpp

示例12: ReleaseDirectKeyboard

void ReleaseDirectKeyboard(void)
{
	if (DIKeyboardOkay)
      {
       lpdiKeyboard->Unacquire();
       DIKeyboardOkay = FALSE;
      }

    if (lpdiKeyboard != NULL)
	  {
       lpdiKeyboard->Release();
	   lpdiKeyboard = NULL;
	  }
}
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:14,代码来源:Di_func.cpp

示例13: input_dinput_set_cooperative_level

/**
 * input_dinput_set_cooperative_level(): Sets the cooperative level.
 * @param hWnd Window to set the cooperative level on.
 * @return 0 on success; non-zero on error.
 */
int input_dinput_set_cooperative_level(HWND hWnd)
{
	// If no hWnd was specified, use the Gens window.
	if (!hWnd)
		hWnd = gens_window;
	
	if (!hWnd || !lpDIDKeyboard /*|| lpDIDMouse*/)
		return -1;
	
	HRESULT rval;
	//rval = lpDIDMouse->SetCooperativeLevel(hWnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND);
	rval = lpDIDKeyboard->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
	if (rval != DI_OK)
	{
		LOG_MSG(input, LOG_MSG_LEVEL_WARNING,
			"lpDIDKeyboard->SetCooperativeLevel() failed.");
		// TODO: Error handling code.
	}
	else
	{
		LOG_MSG(input, LOG_MSG_LEVEL_INFO,
			"lpDIDKeyboard->SetCooperativeLevel() succeeded.");
	}
	
	return 0;
}
开发者ID:salviati,项目名称:gens-gs-debug,代码行数:31,代码来源:input_dinput.cpp

示例14: PisteInput_Hae_Nappaimet

bool PisteInput_Hae_Nappaimet()
{
	HRESULT result;
	bool ok = true;
	
	while (result = PI_lpdikey->GetDeviceState(sizeof(PI_keyboard_state),
		   (LPVOID) PI_keyboard_state) == DIERR_INPUTLOST)
	{
		if (FAILED(result = PI_lpdikey->Acquire()))
		{
			PisteLog_Kirjoita("[Warning] Piste Input: Lost control of keyboard! \n");
			ok = false;
		}
	}
	
	return ok;
}
开发者ID:stt,项目名称:pk2,代码行数:17,代码来源:PisteInput.cpp

示例15: ReleaseDirectMouse

void ReleaseDirectMouse(void)

{
    if (lpdiMouse != NULL)
	  {
       lpdiMouse->Release();
	   lpdiMouse = NULL;
	  }
}
开发者ID:OpenSourcedGames,项目名称:Aliens-vs-Predator,代码行数:9,代码来源:Di_func.cpp


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