本文整理汇总了C++中LPDIRECTINPUTDEVICE8::SetCooperativeLevel方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE8::SetCooperativeLevel方法的具体用法?C++ LPDIRECTINPUTDEVICE8::SetCooperativeLevel怎么用?C++ LPDIRECTINPUTDEVICE8::SetCooperativeLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUTDEVICE8
的用法示例。
在下文中一共展示了LPDIRECTINPUTDEVICE8::SetCooperativeLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: initDIDevice
bool initDIDevice(HINSTANCE hInstance, HWND hWnd)
{
// Initialisation de DirectInput
if(FAILED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pDI, NULL)))
return false;
// Initialisation du clavier
if(FAILED(g_pDI->CreateDevice(GUID_SysKeyboard, &g_pKeyboardDevice, NULL)))
return false;
if(FAILED(g_pKeyboardDevice->SetDataFormat(&c_dfDIKeyboard)))
return false;
if(FAILED(g_pKeyboardDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
return false;
if(FAILED(g_pKeyboardDevice->Acquire()))
return false;
// Initialisation de la souris
if(FAILED(g_pDI->CreateDevice(GUID_SysMouse, &g_pMouseDevice, NULL)))
return false;
if(FAILED(g_pMouseDevice->SetDataFormat(&c_dfDIMouse)))
return false;
if(FAILED(g_pMouseDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_EXCLUSIVE)))
return false;
if(FAILED(g_pMouseDevice->Acquire()))
return false;
return true;
}
示例2: DirectInput_Init
bool DirectInput_Init(HWND hwnd)
{
//initialize DirectInput object
DirectInput8Create(
GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&dinput,
NULL);
//initialize the keyboard
dinput->CreateDevice(GUID_SysKeyboard, &dikeyboard, NULL);
dikeyboard->SetDataFormat(&c_dfDIKeyboard);
dikeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
dikeyboard->Acquire();
//initialize the mouse
dinput->CreateDevice(GUID_SysMouse, &dimouse, NULL);
dimouse->SetDataFormat(&c_dfDIMouse);
dimouse->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
dimouse->Acquire();
d3ddev->ShowCursor(false);
return true;
}
示例3: GutInputInit
int GutInputInit(void)
{
memset(g_pKeyDownFuncs, 0, sizeof(g_pKeyDownFuncs));
memset(g_pKeyUpFuncs, 0, sizeof(g_pKeyUpFuncs));
memset(g_pKeyPressedFuncs, 0, sizeof(g_pKeyPressedFuncs));
int hr;
HWND hwnd = GutGetWindowHandleWin32();
HINSTANCE hinst = GutGetWindowInstanceWin32();
hr = DirectInput8Create( hinst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&g_pDI, NULL);
if ( FAILED(hr) )
return 0;
// create keyboard device
hr = g_pDI->CreateDevice( GUID_SysKeyboard, &g_pKeyboard, NULL );
if ( FAILED(hr) )
return 0;
if ( g_pKeyboard )
{
g_pKeyboard->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
g_pKeyboard->SetDataFormat(&c_dfDIKeyboard);
g_pKeyboard->Acquire();
}
// create mouse device
hr = g_pDI->CreateDevice(GUID_SysMouse, &g_pMouse, NULL);
if ( FAILED(hr) )
return 0;
if ( g_pMouse )
{
g_pMouse->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
g_pMouse->SetDataFormat(&c_dfDIMouse2);
g_pMouse->Acquire();
}
GetCursorPos(&g_op);
ScreenToClient(hwnd, &g_op);
g_mouse = g_op;
// create joystick device
hr = g_pDI->EnumDevices(DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ATTACHEDONLY);
if ( FAILED(hr) )
return 0;
if ( g_pJoystick )
{
g_pJoystick->SetCooperativeLevel(hwnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE );
g_pJoystick->SetDataFormat(&c_dfDIJoystick);
g_pJoystick->Acquire();
}
return 1;
}
示例4: InitKeyboard
//=============================================================================
// キーボードの初期化
//=============================================================================
HRESULT InitKeyboard(HINSTANCE hInst, HWND hWnd)
{
HRESULT hr;
// デバイスオブジェクトを作成
hr = g_pDInput->CreateDevice(GUID_SysKeyboard, &g_pDIDevKeyboard, NULL);
if(FAILED(hr) || g_pDIDevKeyboard == NULL)
{
MessageBox(hWnd, "キーボードがねぇ!", "警告!", MB_ICONWARNING);
return hr;
}
// データフォーマットを設定
hr = g_pDIDevKeyboard->SetDataFormat(&c_dfDIKeyboard);
if(FAILED(hr))
{
MessageBox(hWnd, "キーボードのデータフォーマットを設定できませんでした。", "警告!", MB_ICONWARNING);
return hr;
}
// 協調モードを設定(フォアグラウンド&非排他モード)
hr = g_pDIDevKeyboard->SetCooperativeLevel(hWnd, (DISCL_FOREGROUND | DISCL_NONEXCLUSIVE));
if(FAILED(hr))
{
MessageBox(hWnd, "キーボードの協調モードを設定できませんでした。", "警告!", MB_ICONWARNING);
return hr;
}
// キーボードへのアクセス権を獲得(入力制御開始)
g_pDIDevKeyboard->Acquire();
return S_OK;
}
示例5: INPMouseInit
/////////////////////////////////////
// Name: INPMouseInit
// Purpose: initialize mouse
// if bExclusive, this means
// we don't get actual windows
// mouse location. Use it on
// fullscreen only.
// Output: mouse initialized
// Return: success if so
/////////////////////////////////////
s32 F_API INPMouseInit(void *hMain, u8 bExclusive, iPoint *pBound)
{
INPMouseDestroy();
HRESULT hr;
//create the mouse device
hr = g_pDInput->CreateDevice(GUID_SysMouse, &g_pDMouse, NULL);
if(FAILED(hr))
{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }
//set mouse device as a REAL mouse
hr = g_pDMouse->SetDataFormat(&c_dfDIMouse2);
if(FAILED(hr))
{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }
//set up mouse coop level
u32 coop = g_coopFlag & ~(INP_EXCLUSIVE | INP_NONEXCLUSIVE);
coop |= bExclusive ? INP_EXCLUSIVE : INP_NONEXCLUSIVE;
hr = g_pDMouse->SetCooperativeLevel((HWND)hMain, coop);
if(FAILED(hr))
{ DInputError(hr, L"INPMouseInit"); return RETCODE_FAILURE; }
//acquire mouse device
g_pDMouse->Acquire();
g_bExclusive = bExclusive;
memset(&g_mouseLoc, 0, sizeof(g_mouseLoc));
INPMouseSetBound(pBound);
return RETCODE_SUCCESS;
}
示例6: InitDirectInput
//-----------------------------------------------------------------------------
// Name: InitDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
HRESULT InitDirectInput( HWND hDlg )
{
HRESULT hr;
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
if( FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )
return hr;
// Retrieve the system mouse
if( FAILED( g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ) ) )
{
MessageBox( NULL, TEXT( "Mouse not found. The sample will now exit." ),
TEXT( "DirectInput Sample" ),
MB_ICONERROR | MB_OK );
EndDialog( hDlg, 0 );
return S_OK;
}
// A data format specifies which controls on a device we are interested in,
// and how they should be reported. This tells DInput that we will be
// passing a MouseState structure to IDirectInputDevice::GetDeviceState().
if( FAILED( hr = g_pMouse->SetDataFormat( &g_dfMouse ) ) )
return hr;
// Set the cooperative level to let DInput know how this device should
// interact with the system and with other DInput applications.
if( FAILED( hr = g_pMouse->SetCooperativeLevel( hDlg, DISCL_NONEXCLUSIVE |
DISCL_FOREGROUND ) ) )
return hr;
return S_OK;
}
示例7: DInput_Init_Keyboard
int DInput_Init_Keyboard(void)
{
// this function initializes the keyboard device
// create the keyboard device
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdikey, NULL)!=DI_OK)
return(0);
// set cooperation level
if (lpdikey->SetCooperativeLevel(main_window_handle,
DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
return(0);
// set data format
if (lpdikey->SetDataFormat(&c_dfDIKeyboard)!=DI_OK)
return(0);
// acquire the keyboard
if (lpdikey->Acquire()!=DI_OK)
return(0);
// return success
return(1);
} // end DInput_Init_Keyboard
示例8: open_dx_keyboard
C_RESULT open_dx_keyboard(void)
{
HRESULT hr;
HWND hDlg = GetConsoleHwnd();
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
// Create a DInput object
if (g_pDI==NULL)
if( VP_FAILED( hr = DirectInput8Create( GetModuleHandle( NULL ), DIRECTINPUT_VERSION,
IID_IDirectInput8, ( VOID** )&g_pDI, NULL ) ) )
return hr;
// Create the connection to the keyboard device
g_pDI->CreateDevice(GUID_SysKeyboard, &fDIKeyboard, NULL);
if (fDIKeyboard)
{
fDIKeyboard->SetDataFormat(&c_dfDIKeyboard);
fDIKeyboard->SetCooperativeLevel(hDlg,DISCL_FOREGROUND | DISCL_EXCLUSIVE);
fDIKeyboard->Acquire();
}
return C_OK;
}
示例9: DInput_Init_Mouse
int DInput_Init_Mouse(void)
{
// this function intializes the mouse
// create a mouse device
if (lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL)!=DI_OK)
return(0);
// set cooperation level
// change to EXCLUSIVE FORGROUND for better control
if (lpdimouse->SetCooperativeLevel(main_window_handle,
DISCL_NONEXCLUSIVE | DISCL_BACKGROUND)!=DI_OK)
return(0);
// set data format
if (lpdimouse->SetDataFormat(&c_dfDIMouse)!=DI_OK)
return(0);
// acquire the mouse
if (lpdimouse->Acquire()!=DI_OK)
return(0);
// return success
return(1);
} // end DInput_Init_Mouse
示例10: GetDevice
//------------------------------------------------------
// コントローラー初期化
//------------------------------------------------------
LPDIRECTINPUTDEVICE8 iexInputManager::GetDevice( int n )
{
HRESULT hr;
LPDIRECTINPUTDEVICE8 lpDevice;
// デバイス生成
hr = pDI->CreateDevice( didi[n].guidInstance, &lpDevice, NULL);
if( FAILED(hr) ) return NULL;
if( lpDevice->SetDataFormat( &c_dfDIJoystick2 ) != DI_OK ) return FALSE;
if( lpDevice->SetCooperativeLevel( iexSystem::Window, DISCL_EXCLUSIVE | DISCL_FOREGROUND ) != DI_OK ) return FALSE;
// 自動センタリング無効
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = DIPROPAUTOCENTER_OFF;
lpDevice->SetProperty( DIPROP_AUTOCENTER, &dipdw.diph );
// 各軸設定
lpDevice->EnumObjects(EnumAxes, lpDevice, DIDFT_AXIS);
// 入力制御開始
lpDevice->Acquire();
return lpDevice;
}
示例11: InitDinputDevice
//DirectInputデバイスの初期化
bool Application::InitDinputDevice()
{
//DirectInputデバイスを作成
if (FAILED(directInput->CreateDevice(GUID_SysMouse, &dinputDevice, nullptr)))
return false;
//データフォーマットを設定
if (FAILED(dinputDevice->SetDataFormat(&c_dfDIMouse2)))
return false;
//協調モードを設定
if (FAILED(dinputDevice->SetCooperativeLevel(hWnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND)))
return false;
// 軸モードを設定
DIPROPDWORD diprop;
diprop.diph.dwSize = sizeof(diprop);
diprop.diph.dwHeaderSize = sizeof(diprop.diph);
diprop.diph.dwObj = 0;
diprop.diph.dwHow = DIPH_DEVICE;
diprop.dwData = DIPROPAXISMODE_REL;
if (FAILED(dinputDevice->SetProperty(DIPROP_AXISMODE, &diprop.diph)))
{
MessageBox(NULL, "設定に失敗", "Direct Input Error", MB_OK);
return false;
}
// 入力制御開始
dinputDevice->Acquire();
return true;
}
示例12: EnumJoysticksCallback
BOOL CALLBACK EnumJoysticksCallback( const DIDEVICEINSTANCE* pdidInstance, VOID* pContext )
{
LPDIRECTINPUTDEVICE8 dinJoystick;
// Obtain an interface to the enumerated joystick.
HRESULT hr = din->CreateDevice( pdidInstance->guidInstance, &dinJoystick, NULL );
if ( FAILED( hr ) )
return ( DIENUM_CONTINUE );
dinJoystick->SetDataFormat( &c_dfDIJoystick2 );
HWND hWnd = *( (HWND*)pContext );
dinJoystick->SetCooperativeLevel( hWnd, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND );
unsigned char i = numJoysticks++;
dinJoysticks[i] = dinJoystick;
unsigned int nameLength = strlenW( pdidInstance->tszInstanceName );
char* name = (char*)malloc( nameLength + 1 );
//memcpy( name, pdidInstance->tszInstanceName, nameLength + 1 );
copyWideStringToString( pdidInstance->tszInstanceName, name );
joystickNames[i] = name;
numButtons[i] = 0;
buttonNames[i] = (char**)malloc( 256 );
dinJoystick->EnumObjects( &EnumButtonsCallback, &i, DIDFT_BUTTON );
//return ( DIENUM_STOP );
return ( DIENUM_CONTINUE );
}
示例13: Init
/// a function that Initializes all direct input stuff
void TSRInputSubSystem::Init()
{
#if defined( WIN32 ) || defined( WIN64 )
if ( FAILED( DirectInput8Create( GetModuleHandle( 0 ), DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_lpdi, NULL) ) )
{
TSRFatalError( "Error Creating main direct input object" );
}
if ( FAILED( m_lpdi->CreateDevice( GUID_SysMouse, &m_lpdimouse, NULL ) ) )
{
TSRFatalError( "Error Creating mouse device" );
}
if ( FAILED( m_lpdimouse->SetCooperativeLevel( NULL, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE ) ) )
{
TSRFatalError( "Error Setting mouse cooperative level" );
}
if ( FAILED( m_lpdimouse->SetDataFormat( &c_dfDIMouse ) ) )
{
TSRFatalError( "Error setting mouse data fromat" );
}
if ( FAILED ( m_lpdimouse->Acquire() ) )
{
TSRFatalError( "error aquiring mouse" );
}
#endif
}
示例14: InitDirectInput
//-----------------------------------------------------------------------------
// Name: InitDirectInput()
// Desc: Initialize the DirectInput variables.
//-----------------------------------------------------------------------------
HRESULT InitDirectInput( HWND hWnd )
{
HRESULT hr;
// Register with the DirectInput subsystem and get a pointer
// to a IDirectInput interface we can use.
// Create a DInput object
if( FAILED( hr = DirectInput8Create( GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8, (VOID**)&g_pDI, NULL ) ) )
return hr;
// Obtain an interface to the system mouse device.
if( FAILED( hr = g_pDI->CreateDevice( GUID_SysMouse, &g_pMouse, NULL ) ) )
return hr;
// Set the data format to "mouse format" - a predefined data 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 a
// DIMOUSESTATE structure to IDirectInputDevice::GetDeviceState.
if( FAILED( hr = g_pMouse->SetDataFormat( &c_dfDIMouse ) ) )
return hr;
// Set the cooperativity level to let DirectInput know how
// this device should interact with the system and with other
// DirectInput applications.
if( FAILED( hr = g_pMouse->SetCooperativeLevel( hWnd,
DISCL_EXCLUSIVE|DISCL_FOREGROUND ) ) )
return hr;
// Create a win32 event which is signaled when mouse data is availible
g_hMouseEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
if( NULL == g_hMouseEvent )
return E_FAIL;
// Give the event to the mouse device
if( FAILED( hr = g_pMouse->SetEventNotification( g_hMouseEvent ) ) )
return hr;
// Setup the buffer size for the mouse data
DIPROPDWORD dipdw;
dipdw.diph.dwSize = sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipdw.diph.dwObj = 0;
dipdw.diph.dwHow = DIPH_DEVICE;
dipdw.dwData = SAMPLE_BUFFER_SIZE; // Arbitary buffer size
if( FAILED( hr = g_pMouse->SetProperty( DIPROP_BUFFERSIZE, &dipdw.diph ) ) )
return hr;
// Not necessary, but nice for left handed users that have
// their swapped mouse buttons
g_bSwapMouseButtons = GetSystemMetrics( SM_SWAPBUTTON );
return S_OK;
}
示例15: initialize
void initialize(HWND hwnd)
{
DirectInput8Create(
GetModuleHandle(NULL),
DIRECTINPUT_VERSION,
IID_IDirectInput8,
(VOID**)&directInput,
NULL);
directInput->CreateDevice(GUID_SysMouse, &mouseDevice, 0);
mouseDevice->SetDataFormat(&c_dfDIMouse);
mouseDevice->SetCooperativeLevel(hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE );
mouseDevice->Acquire();
directInput->CreateDevice( GUID_SysKeyboard, &keyboardDevice, 0);
keyboardDevice->SetDataFormat(&c_dfDIKeyboard);
keyboardDevice->SetCooperativeLevel(hwnd, DISCL_BACKGROUND | DISCL_NONEXCLUSIVE );
keyboardDevice->Acquire();
}