int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
MSG msg;
staticint iTickTrigger = 0;
int iTickCount;
if (GameInitialize(hInstance))
{
// Initialize the game engine
if (!GameEngine::GetEngine()->Initialize(iCmdShow))
return FALSE;
// Enter the main message loop
while (TRUE)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
// Process the message
if (msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
// Make sure the game engine isn't sleeping
if (!GameEngine::GetEngine()->GetSleep())
{
// Check the tick count to see if a game cycle has elapsed
iTickCount = GetTickCount();
if (iTickCount > iTickTrigger)
{
iTickTrigger = iTickCount +
GameEngine::GetEngine()->GetFrameDelay();
HandleKeys();
GameEngine::GetEngine()->CheckJoystick();
GameCycle();
}
}
}
}
return (int)msg.wParam;
}
// End the game
GameEnd();
return TRUE;
}
As far as i can tell WinMain() is returning a TRUE value, i do see the "return (int)msg.wParam;" but its not where it should be???? This is out of my book. The program works with this btw.
There isn't anything wrong with having more than one 'return' in your functions, including main (except that it might sometimes make them hard to understand) nor with returning something else than 0 from main, though a value other than 0 is usually understood as some sort of failure.
This code returns msg.wParam if GameInitialize succeeds and 1 otherwise.
What does that have to do with anything? I am telling you, put that book of yours away and learn programming before you start reading it again. There is nothing wrong with seeking help once in a while, but quite frankly I get the impression you go here after every single chapter because you have absolutely no idea what is going on.
The type "BOOL" is a Windows type, and it's just a typedef for int.
So even though it may appear that you're returning different data types, under the hood, you are in fact returning what the method declaration is expecting. I'd question returning a boolean value from a method that is declared to return an int as well.
I can't definitively say that TRUE == 1, only that TRUE != 0.
Welcome to Windows Programming. This is the first of many windows-isms that you'll encounter. Be prepared to be looking through the WINAPI documentation 95% of the time and coding the other 5% until you memorize the many hacks decisions that Microsoft has made to preserve backward compatibility.
That's not particular to Windows programming. Any non-zero numerical value is considered true in a boolean context in C and in C++ (and in many other languages).