I have a C ++ program that lists all input devices (using direct input) at the beginning of the program. If the program is running, and then I connect another controller, this controller will not be recognized until the program is restarted. Does anyone know of an event that I can use that will cause my program to list all devices after a new one is connected?
This article discusses ways to detect changes to the playing field. First of all, you can process the WM_DEVICECHANGE message and check wParam for DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE . It seems that in order to get them as wParam s, you must first call RegisterDeviceNotification .
WM_DEVICECHANGE
wParam
DBT_DEVICEARRIVAL
DBT_DEVICEREMOVECOMPLETE
RegisterDeviceNotification
An example article on how to do this is as follows:
DEV_BROADCAST_DEVICEINTERFACE notificationFilter; ZeroMemory(¬ificationFilter, sizeof(notificationFilter)); notificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; notificationFilter.dbcc_size = sizeof(notificationFilter); HDEVNOTIFY hDevNotify; hDevNotify = RegisterDeviceNotification(m_hWnd, ¬ificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES); if(hDevNotify == NULL) { // do some error handling }
The only thing you need to pay attention to is the minimum supported OS for this - XP, so you need to add the appropriate #define for this before including the Windows headers.
#define
Depending on what you want to do, you might not even have to call this function first. Instead, you can simply check DBT_DEVNODES_CHANGED to not distinguish between a connected or disconnected device. This might save some code if you don't care.
DBT_DEVNODES_CHANGED
Source: https://habr.com/ru/post/944904/More articles:Find the number of decimal digits of a variable in MATLAB - matlabHiDPI Mode Detection - qtWill I receive GCM messages if Android kills my application and if I do Force Close from the settings? - javaResourcePool could not get the resource from its main factory or source - javaPackage for formatting numerical values ββin reproducible studies - rKarma + Rails: file structure? - ruby-on-railsWhy does java have a Type when it already has an Object? - javahttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/944907/jquery-adding-additional-pixels-to-the-scrolltop&usg=ALkJrhhmTN2VTQld53pLixQ7zV6pePC3GAggplot 2 "Error: discrete value set for continuous scaling" - rType_traits segmentation error with std :: string - c ++All Articles