-
Two things for clarity;
1. PeekMessage() will return imediately from the msg que, GetMessge() will wait in the que until a message arrives.
So PeekMessage() is used in (game) loops where the main task is not just getting user input.
2. GetAsyncKeyState() gets the current state of the key. The message may not yet have been posted to the que so beware you do not process a second time.
GetKeyboardState() will get all the keys. and record the results into an array. the array can then be indexed by the VK_ key codes ie
Code:
BYTE byteKeyArray[256];
GetKeyboardState(&byteKeyArray);
UpdateShip(byteKeyArray[VK_UP], byteKeyArray[VK_DOWN], ect );
-
One NASTY flaw in all your code is your window procedure, it uses the break; command instead of return 0;. If your window procedure doesn't return anything, which it won't for trapped messages, things can get messy. Instead of this:
switch (message)
{
case WM_PAINT:
// Paint
break;
case WM_DESTROY:
PostQuitMessage (0);
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
Try this:
switch (message)
{
case WM_PAINT:
// Paint
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam);