will I have to place a call to a function that calculates something (for example the next chess move)? Inside the GetMessage Loop? Or will I have to use PeekMessage? Or should I call that chess-function out of WndProc?
Printable View
will I have to place a call to a function that calculates something (for example the next chess move)? Inside the GetMessage Loop? Or will I have to use PeekMessage? Or should I call that chess-function out of WndProc?
>>Or should I call that chess-function out of WndProc?<<
Yes you should put it there at WndProc :) That's the function you should use to handle any events (or commands) in your prog.
:) You're making a Chess game?Code:LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message) {
/*...other cases here...*/
case WM_COMMAND:
switch(wParam) {
/*...other cases here too...*/
case ID_CALCULATE_BUTTON: CalculateMove(/*...etc...*/); return 1;
/*...you know what comes next...*/
}
/*...here too...*/
}
}
A chess move will only occur AFTER the users move. Put it in response to the user moving (ie part of the processing of the users move is the computer move).
PeekMessage() will return to the message loop (or pump) if there is no message.
GetMessage() waits until there is a message before returning.
If writing a game like a FPS you need to do things in between the users actions (ie update the monsters actions) so should use PeekMessage()
A chess game can wait until the user responds so I would use GetMessage()