Message Loop in MFC

Started by
2 comments, last by Enfekted 20 years, 2 months ago
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]
Advertisement
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.
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
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]
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;}

This topic is closed to new replies.

Advertisement