My current approach leaves the keypress checking to the main loop, and moves the actual HUD updates to a TimerProc function. I have to create a timer with SetTimer and pass it the address of TimerProc, so during my main loop I also check for messages, and translate/dispatch the WM_TIMER messages. Dispatching the WM_TIMER message, if it was caused by the timer I created, will call TimerProc!
Below is my new and improved main() function, as well as my current TimerProc function.
void CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime){ static bool timestatinc = false; //Because this function is called every 500ms, I need to keep track //of whena full second has passed. Only then do I update the time data. if (timestatinc) ++GameInfo.time; GameInfo.score += 10; hud.Draw(0, 0); timestatinc = !timestatinc;}int main(){ Init(); hud.Draw(0, 0); if (!SetTimer(NULL, 1, 500, &TimerProc)) return 1; while (true) { int vkey = CheckForKeypress(); if (vkey == VK_ESCAPE) break; MSG msg; if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_TIMER) { TranslateMessage(&msg); DispatchMessage(&msg); } } } KillTimer(NULL, 1);}
I'm still not sure what the commenters meant in my last post, but I'm pretty sure this approach will be sufficient for Cripes!. Thanks for the input though, always great to have! *hint hint*
EDIT: In other news, my grandmother let me pick out and buy three books, which totalled to $140 total. I know, it's mean for me to do that, but she let me AND she said it would be an early birthday present. "As long as you read them and learn from them, I'm fine!" So, yeah. I'm now the proud-to-semi-proud owner of World of Warcraft Programming (addons and such), Breaking Into the Game Industry (my favorite so far!), and Windows From C/C++ (at $70, I should like this best, but... I don't. It's handy though, and I got the SetTimer idea from it!)