Ok, I've been trying the Raw input stuff, but now I'm stuck again
Firstly, my Input class has a CheckInput method that requires a LPARAM variable from the games message handler. How am I supposed to be able to access it? Here's the code:
[source lang="cpp"]#include <Windows.h>#include "Main.h"#include "Graphics.h"#include "Input.h"#include "Player.h"LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){switch (message){ case WM_DESTROY: PostQuitMessage(0); return 0;}return DefWindowProc(hWnd, message, wParam, lParam);}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){WNDCLASSEX wc;ZeroMemory(&wc, sizeof(WNDCLASSEX));wc.cbSize = sizeof(WNDCLASSEX);wc.hInstance = hInstance;wc.lpfnWndProc = WindowProc;wc.lpszClassName = L"AvoidBallClass";wc.style = CS_VREDRAW | CS_HREDRAW;RegisterClassEx(&wc);HWND hWnd;hWnd = CreateWindowEx(NULL, L"AvoidBallClass", L"AvoidBall", WS_OVERLAPPED, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);ShowWindow(hWnd, nCmdShow);MSG msg;Graphics* graphics = new Graphics(hWnd);Input* input = new Input();Player* player = new Player(*graphics, 100, 100);while (true){ while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } input->CheckInput(lParam); graphics->Begin(); graphics->Draw(*player->sprite, player->x, player->y); graphics->End();}// TODO: Clean up resources.return msg.wParam;}[/source]
As you can see on row 50, I need to access the lParam parameter from the WindowProc method. How can I do that?
Also, this is my Input class. Does this seem to be correct, or have I missed anything? (havn't managed to test it due to the above problem). Code:
[source cpp="cpp"]#include <Windows.h>#include "Input.h"#include "Main.h"Input::Input(){RAWINPUTDEVICE rid[1];rid[0].usUsagePage = 1;rid[0].usUsage = 6;rid[0].dwFlags = 0;rid[0].hwndTarget = NULL;RegisterRawInputDevices(rid, 1, sizeof(RAWINPUTDEVICE));}Input::~Input(void){}void Input::CheckInput(LPARAM lParam){UINT bufferSize;GetRawInputData((HRAWINPUT)lParam, RID_INPUT, NULL, &bufferSize, sizeof (RAWINPUTHEADER));BYTE* buffer=new BYTE[bufferSize];GetRawInputData((HRAWINPUT)lParam, RID_INPUT, (LPVOID)buffer, &bufferSize, sizeof (RAWINPUTHEADER));RAWINPUT* raw = (RAWINPUT*) buffer;if (raw->header.dwType == RIM_TYPEKEYBOARD){ USHORT keyCode = raw->data.keyboard.VKey; switch (keyCode) { case VK_LEFT: MessageBox(NULL, L"Left", NULL, NULL); break; case VK_RIGHT: MessageBox(NULL, L"Right", NULL, NULL); break; case VK_UP: MessageBox(NULL, L"Up", NULL, NULL); break; case VK_DOWN: MessageBox(NULL, L"Down", NULL, NULL); break; }}}[/source]