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