bool Mouse3DInput::initializeRawInput(HWND hwndTarget) { m_window = hwndTarget; // Simply fail if there is no window if (!hwndTarget) return false; unsigned int numDevices = 0; PRAWINPUTDEVICE devicesToRegister = GetDevicesToRegister(numDevices); if (numDevices == 0) return false; // Get OS version OSVERSIONINFO osvi = {sizeof(OSVERSIONINFO),0}; ::GetVersionEx(&osvi); unsigned int cbSize = sizeof(devicesToRegister[0]); for (size_t i = 0; i < numDevices; i++) { // Set the target window to use //devicesToRegister[i].hwndTarget = hwndTarget; // If Vista or newer, enable receiving the WM_INPUT_DEVICE_CHANGE message. if (osvi.dwMajorVersion >= 6) devicesToRegister[i].dwFlags |= RIDEV_DEVNOTIFY; } return (::RegisterRawInputDevices(devicesToRegister, numDevices, cbSize) != FALSE); }
// Initialize the window to recieve raw-input messages // This needs to be called initially so that Windows will send the messages from the 3D mouse to the window. bool ConnexionClient::InitializeRawInput(HWND hwndTarget) { fWindow = hwndTarget; // Simply fail if there is no window if (!hwndTarget) { return false; } unsigned int numDevices = 0; PRAWINPUTDEVICE devicesToRegister = GetDevicesToRegister(&numDevices); if (numDevices == 0) { return false; } unsigned int cbSize = sizeof(devicesToRegister[0]); for (size_t i = 0; i < numDevices; i++) { // Set the target window to use //devicesToRegister[i].hwndTarget = hwndTarget; // If Vista or newer, enable receiving the WM_INPUT_DEVICE_CHANGE message. if (IsWindowsVistaOrGreater()) { devicesToRegister[i].dwFlags |= RIDEV_DEVNOTIFY; } } return (::RegisterRawInputDevices(devicesToRegister, numDevices, cbSize) != FALSE); }
bool Mouse3DInput::DeviceAvailable() { unsigned int numDevicesOfInterest = 0; PRAWINPUTDEVICE devicesToRegister = GetDevicesToRegister(numDevicesOfInterest); unsigned int nDevices = 0; if (::GetRawInputDeviceList(NULL, &nDevices, sizeof(RAWINPUTDEVICELIST)) != 0 || nDevices == 0) { //no device detected return false; } std::vector<RAWINPUTDEVICELIST> rawInputDeviceList(nDevices); if (::GetRawInputDeviceList(&rawInputDeviceList[0], &nDevices, sizeof(RAWINPUTDEVICELIST)) == static_cast<unsigned int>(-1)) { return false; } for (unsigned int i = 0; i < nDevices; ++i) { unsigned int cbSize = sizeof(RID_DEVICE_INFO); RID_DEVICE_INFO rdi = { cbSize }; if (GetRawInputDeviceInfo(rawInputDeviceList[i].hDevice, RIDI_DEVICEINFO, &rdi, &cbSize) > 0) { //skip non HID and non logitec (3DConnexion) devices if (rdi.dwType != RIM_TYPEHID || rdi.hid.dwVendorId != LOGITECH_VENDOR_ID) continue; //check if devices matches Multi-axis Controller for (unsigned int j = 0; j < numDevicesOfInterest; ++j) { if (devicesToRegister[j].usUsage == rdi.hid.usUsage && devicesToRegister[j].usUsagePage == rdi.hid.usUsagePage) return true; } } } return false; }