本文整理汇总了C++中LPDIRECTINPUTDEVICE::SetProperty方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTINPUTDEVICE::SetProperty方法的具体用法?C++ LPDIRECTINPUTDEVICE::SetProperty怎么用?C++ LPDIRECTINPUTDEVICE::SetProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTINPUTDEVICE
的用法示例。
在下文中一共展示了LPDIRECTINPUTDEVICE::SetProperty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: 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;
}