I have tested making a default window, and I have tested a message-only window both on a separate thread from the main thread.
The goal is to receive WM_INPUT
from HID devices from outside the main thread. The reason is that the main thread loop will run at a much slower rate than the needed rate to process inputs.
Both windows seem to work so long as the main window of the main thread isn't the active window.
What are the possible solutions for this issue?
Edit:
I didn't add the code because it is basically boilerplate code, but since many commented wanting to see some code, I will add it as it might really be helpful.
//FIRST: CLASS REGISTRATION:
WNDCLASSEXW wcex;
wchar_t local_name[] = L"ClassGenericName";
wcsncat(local_name,
std::to_wstring(GetCurrentThreadId()).c_str(),
std::to_wstring(GetCurrentThreadId()).size());
//You can ignore naming process as it was made to make more than one window for more than one thread, just for testing purposes.
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_WINAPITEST));
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_WINAPITEST);
wcex.lpszClassName = local_name;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
RegisterClassExW(&wcex);
hWnd = CreateWindowEx(0, wcex.lpszClassName, L"no title", 0, 0, 0, 0, 0, HWND_MESSAGE, 0, 0, 0);
ShowWindow(hWnd, 3);//Testing, I switch it on and off.
UpdateWindow(hWnd);
//SECOND: DEVICE REGISTRATION:
RAWINPUTDEVICE RID;
RID.usUsagePage = 0x01;
RID.usUsage = 0x05;
RID.dwFlags = 0;
RID.hwndTarget = 0;
RegisterRawInputDevices(&RID, 1, sizeof(RID));
//THIRD: THREAD FUNCTION MESSAGE LOOP.
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_WINAPITEST));
MSG msg;
while (GetMessageW(&msg, nullptr, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
//FOURTH: WINDOW PROCEDURE MESSAGE PROCESSING.
//I don't think I need to add this as it is boilerplate and tested to work all the time. If wanted I'd add it tho.
//FIVE: Thanks for helpful comments. My bad for not adding code ahead of time.