本文整理汇总了C++中LPDIRECTINPUTDEVICE::SetCooperativeLevel方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE::SetCooperativeLevel方法的具体用法?C++ LPDIRECTINPUTDEVICE::SetCooperativeLevel怎么用?C++ LPDIRECTINPUTDEVICE::SetCooperativeLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUTDEVICE
的用法示例。
在下文中一共展示了LPDIRECTINPUTDEVICE::SetCooperativeLevel方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例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;
}
示例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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: di_init
//.........这里部分代码省略.........
* 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:
*
* DISCL_NONEXCLUSIVE
*
* Retrieve keyboard data when acquired, not interfering
* with any other applications which are reading keyboard
* data.
*
* DISCL_FOREGROUND
*
* If the user switches away from our application,
* automatically release the keyboard back to the system.
*
*/
hr = Di_keyboard->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_keyboard->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);
Di_thread = CreateThread(NULL, 1024, (LPTHREAD_START_ROUTINE)di_process, NULL, 0, &Di_thread_id);
Assert( Di_thread != NULL );
SetThreadPriority(Di_thread, THREAD_PRIORITY_HIGHEST);
hr = Di_keyboard->SetEventNotification(Di_event);
if (FAILED(hr)) {
mprintf(( "SetEventNotification failed\n" ));
return FALSE;
}
Di_keyboard->Acquire();
return TRUE;
}
示例9: 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;
}