MFC Message Loop and GLView refresh

Hello!
After 2 years of experiments on GL+Win32
I’m developing an Fantasy RPG, with OpengGL
rendering the world on a view window, and MFC managing my GUI.
Now:
I overridden my CGLRpgApp::Run() and added
code to refresh my GL (wglMakCurrent,Draw,SwapBuffers) and it seemed the application caught an endless loop drawing on and on blocking the GUI managing.

the code is:

ASSERT_VALID(this);

// for tracking the idle time state
BOOL bIdle = TRUE;
LONG lIdleCount = 0;

// acquire and dispatch messages until a WM_QUIT message is received.
for (; [img]http://www.opengl.org/discussion_boards/ubb/wink.gif[/img]
{
	// phase1: check to see if we can do idle work
	while (bIdle &&
		!::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE))
	{
		// call OnIdle while in bIdle state
		if (!OnIdle(lIdleCount++))
			bIdle = FALSE; // assume "no idle" state
	}

	// phase2: pump messages while available
	do
	{
		// pump message, but quit on WM_QUIT
		if (!PumpMessage())
			return ExitInstance();

		// reset "no idle" state after pumping "normal" message
		if (IsIdleMessage(&m_msgCur))
		{
			bIdle = TRUE;
			lIdleCount = 0;
		}

//HERE ADDED CODE
wglMakCurrent(…);
glClear();// just a blackened window
SwapBuffers(…);
wglMakCurrent(NULL,NULL);

	} while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE));
}

ASSERT(FALSE);  // not reachable

Done!
I moved the drawing code at the very end of the for(;:wink: loop and replaced the do{…}while() with a while(){…} loop.