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


C++ LPDIRECTINPUT类代码示例

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


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

示例1: WinMain

int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   PSTR      pCmdLine,
                   int       nShowCmd)
{
  HRESULT result = CoInitialize(0);
  LPDIRECTINPUT directinput;

  if (FAILED(result))
    {
      std::cerr << "CL_DisplayWindow_Win32: Damn murphy must hate you. CoInitialize failed!" << std::endl;
    }

  result = CoCreateInstance(CLSID_DirectInput, 0, CLSCTX_INPROC_SERVER, IID_IDirectInput, (LPVOID *) &directinput);
  if (FAILED(result))
    {
      std::cerr << "FAILURE" << std::endl;
    }
  else
    {
      std::cerr << "SUCCESS" << std::endl;
      result = directinput->Initialize(GetModuleHandle(0), DIRECTINPUT_VERSION);
    }

  if (!InitWindowsApp(hInstance, nShowCmd))
    {
      ::MessageBox(0, "Init - Failed", "Error", MB_OK);
      return 0;
    }

  return Run();
}
开发者ID:icebreaker,项目名称:xboxdrv,代码行数:32,代码来源:hello_world.cpp

示例2: HookDirectInput

int HookDirectInput(HMODULE module, int version)
{
	HINSTANCE hinst;
	void *tmp;
	LPDIRECTINPUT lpdi;
	const GUID di7 = {0x9A4CB684,0x236D,0x11D3,0x8E,0x9D,0x00,0xC0,0x4F,0x68,0x44,0xAE};
	const GUID di8 = {0xBF798030,0x483A,0x4DA2,0xAA,0x99,0x5D,0x64,0xED,0x36,0x97,0x00};

	tmp = HookAPI(module, "dinput.dll", NULL, "DirectInputCreateA", extDirectInputCreate);
	if(tmp) pDirectInputCreate = (DirectInputCreate_Type)tmp;
	tmp = HookAPI(module, "dinput.dll", NULL, "DirectInputCreateW", extDirectInputCreate);
	if(tmp) pDirectInputCreate = (DirectInputCreate_Type)tmp;
	tmp = HookAPI(module, "dinput.dll", NULL, "DirectInputCreateEx", extDirectInputCreateEx);
	if(tmp) pDirectInputCreateEx = (DirectInputCreateEx_Type)tmp;
	tmp = HookAPI(module, "dinput8.dll", NULL, "DirectInput8Create", extDirectInput8Create);
	if(tmp) pDirectInputCreateEx = (DirectInputCreateEx_Type)tmp;
	if(!pDirectInputCreate && !pDirectInputCreateEx){
		if(version < 8){
			hinst = LoadLibrary("dinput.dll");
			pDirectInputCreate =
				(DirectInputCreate_Type)GetProcAddress(hinst, "DirectInputCreateA");
			if(pDirectInputCreate)
				if(!extDirectInputCreate(GetModuleHandle(0), DIRECTINPUT_VERSION,
					&lpdi, 0)) lpdi->Release();
			pDirectInputCreateEx =
				(DirectInputCreateEx_Type)GetProcAddress(hinst, "DirectInputCreateEx");
			if(pDirectInputCreateEx)
				if(!extDirectInputCreateEx(GetModuleHandle(0), DIRECTINPUT_VERSION,
					di7, (void **)&lpdi, 0)) lpdi->Release();
		}
		else{
			hinst = LoadLibrary("dinput8.dll");
			pDirectInputCreateEx =
				(DirectInputCreateEx_Type)GetProcAddress(hinst, "DirectInput8Create");
			if(pDirectInputCreateEx)
				if(!extDirectInputCreateEx(GetModuleHandle(0), DIRECTINPUT_VERSION,
					di8, (void **)&lpdi, 0)) lpdi->Release();
		}
	}
	if(pDirectInputCreate || pDirectInputCreateEx) return 1;
	return 0;
}
开发者ID:xmoeproject,项目名称:X-moe,代码行数:42,代码来源:hdinput.cpp

示例3: enumerate

// Hook on joystick
void JoystickHandler::enumerate(LPDIRECTINPUT di, DWORD dwDevType = DI8DEVTYPE_JOYSTICK, LPCDIDATAFORMAT lpdf = &c_dfDIJoystick2, DWORD dwFlags = DIEDFL_ATTACHEDONLY, int maxEntry = 16) {
        clear();
 
        entry           = new Entry [maxEntry];
        this->di        = di;
        this->maxEntry  = maxEntry;
        nEntry          = 0;
        this->lpdf      = lpdf;
	
		// Callbacks to DIEnumDevicesCallback_static
        di->EnumDevices(dwDevType, DIEnumDevicesCallback_static, this, dwFlags);
 
        this->di        = 0;
}
开发者ID:rafel,项目名称:2.5D,代码行数:15,代码来源:JoystickHandler.cpp

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

示例5: Initialize

bool MouseMG::Initialize(const LPDIRECTINPUT pDInput, const HWND hWnd)
	{
	hr = pDInput->CreateDevice(GUID_SysMouse , &pDInputMouse, NULL);
	if( FAILED(hr) )
		return false;
	
	hr = pDInputMouse->SetDataFormat( &c_dfDIMouse );
	if( FAILED(hr) )
		return false;

	hr = pDInputMouse->SetCooperativeLevel(hWnd, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE);
	if( FAILED(hr) )
		return false;

	hr = pDInputMouse->Acquire();
	if( FAILED(hr) )
		return false;
	return true;
	}
开发者ID:bobxiv,项目名称:ICCore,代码行数:19,代码来源:Mouse.cpp

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

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

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

示例9: DirectInput_Init

int DirectInput_Init(void)
{
    HRESULT hr;

    if(dInput || dInput3) return true;

    // Create the DirectInput interface instance. Try version 8 first.
    if(FAILED(hr = CoCreateInstance(CLSID_DirectInput8, NULL, CLSCTX_INPROC_SERVER,
                                    IID_IDirectInput8, (LPVOID*)&dInput)) ||
       FAILED(hr = dInput->Initialize(app.hInstance, DIRECTINPUT_VERSION)))
    {
        Con_Message("DirectInput 8 init failed (0x%x).", hr);

        // Try the older version 3 interface instead.
        // I'm not sure if this works correctly.
        if(FAILED(hr = CoCreateInstance(CLSID_DirectInput, NULL, CLSCTX_INPROC_SERVER,
                                        IID_IDirectInput2W, (LPVOID*)&dInput3)) ||
           FAILED(hr = dInput3->Initialize(app.hInstance, 0x0300)))
        {
            Con_Message("Failed to create DirectInput 3 object (0x%x).", hr);
            return false;
        }

        Con_Message("Using DirectInput 3.");
    }

    if(!dInput && !dInput3)
    {
        Con_Message(" DirectInput init failed.");
        return false;
    }

    return true;
}
开发者ID:cmbruns,项目名称:Doomsday-Engine,代码行数:34,代码来源:directinput.cpp

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

示例11: ReleaseDirectInput

void ReleaseDirectInput(void)

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

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

示例13: ScanJoystickDevices

int CPPJoyJoyDlg::ScanJoystickDevices (void)
{
 int	JoyCount;
 int	Count;
 int	Index;

 for (JoyCount=0;JoyCount<(sizeof(did)/sizeof(*did));JoyCount++)
 {
  if (did[JoyCount])
  {
   // do we want to unacquire here too??
   did[JoyCount]->Release();
  }
  did[JoyCount]= NULL;
 }

 memset (JoystickName,0,sizeof(JoystickName));
 memset (JoystickGUID,0,sizeof(JoystickGUID));
 JoystickCount= 0;

 for (Count=0;Count<8;Count++)
 {
  m_AxisJoy[Count]->ResetContent();
  Index= m_AxisJoy[Count]->AddString("<clear>");
  m_AxisJoy[Count]->SetItemData(Index,-1);
 }

 for (Count=0;Count<16;Count++)
 {
  m_ButJoy[Count]->ResetContent();
  Index= m_ButJoy[Count]->AddString("<clear>");
  m_ButJoy[Count]->SetItemData(Index,-1);
 }

 if (di->EnumDevices(DIDEVTYPE_JOYSTICK,DIEnumDevicesProc,NULL,DIEDFL_ALLDEVICES)!=DI_OK)
  return 0;

 for (JoyCount=0;JoyCount<JoystickCount;JoyCount++)
 {
  for (Count=0;Count<8;Count++)
  {
   Index= m_AxisJoy[Count]->AddString(JoystickName[JoyCount]);
   m_AxisJoy[Count]->SetItemData(Index,JoyCount);
  }

  for (Count=0;Count<16;Count++)
  {
   Index= m_ButJoy[Count]->AddString(JoystickName[JoyCount]);
   m_ButJoy[Count]->SetItemData(Index,JoyCount);
  }
 }

 return 1;
}
开发者ID:Cyborg11,项目名称:PPJoy,代码行数:54,代码来源:PPJoyJoyDlg.cpp

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

示例15: input_dinput_add_joysticks_to_listbox

/**
 * input_dinput_add_joysticks_to_listbox(): Enumerate joysticks and add them to a listbox.
 * @param lstBox Listbox to add the joystick information to.
 */
void input_dinput_add_joysticks_to_listbox(HWND lstBox)
{
	if (!lpDI || input_dinput_joystick_error)
		return;
	
	// Initialize the "Add Joysticks" counter.
	input_dinput_add_joysticks_count = 0;
	
	// Enumerate the joysticks to get their names.
	// TODO: Somehow add this to the first EnumDevices().
	lpDI->EnumDevices(DIDEVTYPE_JOYSTICK,
			  &input_dinput_callback_add_joysticks_to_listbox,
			  lstBox, DIEDFL_ATTACHEDONLY);
}
开发者ID:salviati,项目名称:gens-gs-debug,代码行数:18,代码来源:input_dinput.cpp


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