我不确定我能做到这一点。我不熟悉窗口编程。我想区分这些鼠标或触摸消息中来自哪个设备。以下代码在DLL中,DLL是一个DLL文件钩。
MSG* pMsg = (MSG*)lparam;
if (msg != 0 && msg2 != 0 && pMsg->message != msg && pMsg->message != msg2 )
{
if (pMsg->message == WM_TOUCH || (pMsg->message >= WM_MOUSEFIRST && pMsg->message <= WM_MOUSELAST )) {
SendNotifyMessage(dstWnd, msg, (WPARAM)pMsg->hwnd, pMsg->message);
SendNotifyMessage(dstWnd, msg2, pMsg->wParam, pMsg->lParam);
//if(callBackFunc != NULL) callBackFunc("Hook Message: ");
if (pMsg->message == WM_TOUCH) {
if (callBackFunc != NULL) callBackFunc("Hook Message: WM_LBUTTONDOWN");
translate(wparam,lparam);
//pMsg->message = WM_NULL;
}
}
}
void translate(WPARAM wParam, LPARAM lParam)
{
UINT rawDatasSize(0);
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &rawDatasSize, sizeof(RAWINPUTHEADER));
vector<BYTE> buffer;
buffer.resize(32);
DWORD err1 = GetLastError();
PRAWINPUT pRawInput = (PRAWINPUT) & (buffer[0]);
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, pRawInput, &rawDatasSize, sizeof(RAWINPUTHEADER));
RID_DEVICE_INFO deviceInfo;
deviceInfo.cbSize = sizeof(RID_DEVICE_INFO);
UINT infoSize = deviceInfo.cbSize;
UINT result = GetRawInputDeviceInfo(pRawInput->header.hDevice, RIDI_DEVICEINFO, (LPVOID)&deviceInfo, &infoSize);
DWORD err = GetLastError();
if (pRawInput->header.dwType == RIM_TYPEHID)
{
unsigned long long version = (unsigned long long)deviceInfo.hid.dwVersionNumber;
unsigned long long vid = (unsigned long long)deviceInfo.hid.dwVendorId;
unsigned long long pid = (unsigned long long)deviceInfo.hid.dwProductId;
cout<< "version: " << version << endl;
cout<< "vid: " << vid << endl;
cout<< "pid: " << pid << endl;
//unsigned long long deviceId = (version << 32) | (vid << 16) | pid;
}
}
rawDatasSize始终为0。err始终为6。那么我错了吗?