Archived

This topic is now archived and is closed to further replies.

Enfekted

Message Loop in MFC

Recommended Posts

I'm having a small problem getting my game loop to work properly using MFC. I use to following code: I use to use the following code: I am trying to do the equivalent of the following code using MFC.
while( true )
{
  if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  {
    TranslateMessage( &msg );
    DispatchMessage( &msg );

    if (msg.message == WM_QUIT) break;
  }
  else
  {
    UpdateGame();
  }
}
Currently I'm doing this: (CClientSystemApp is a derivation of CWinApp)
BOOL CClientSystemApp::PumpMessage()
{
	UpdateGame();
	return CWinApp::PumpMessage();
}
But I don't think this is the right place for it. It seems to be waiting for messages before updating the game. Does anyone know where I should put this function call using MFC? Thanks for your help! [edited by - enfekted on January 25, 2004 4:02:10 PM] [edited by - enfekted on January 25, 2004 4:03:26 PM] [edited by - enfekted on January 25, 2004 5:04:22 PM] [edited by - enfekted on January 25, 2004 5:08:37 PM] [edited by - enfekted on January 25, 2004 5:29:27 PM]

Share this post


Link to post
Share on other sites
Which function contains the code is the code in the first source box?


Windows 95 - 32 bit extensions and a graphical shell for a 16 bit patch
to an 8 bit operating system originally coded for a 4 bit microprocessor,
written by a 2 bit company that can''t stand 1 bit of competition.

Share this post


Link to post
Share on other sites
sorry, typo.
I should change that.

I am currently trying to use the second block of code now, but its not working quite right. I've also tried overloading OnIdle() and Run(), but same problem keeps happening.


[edited by - enfekted on January 25, 2004 5:06:35 PM]

Share this post


Link to post
Share on other sites
AHHA!!!

I figured it out. Need to return 1 to tell windows to call OnIdle() again next chance it gets.

BOOL CClientSystemApp::OnIdle(LONG lCount)
{
UpdateGame()
CWinApp::OnIdle(lCount);
return 1;
}

Share this post


Link to post
Share on other sites