MFC + OpenGL freezes

Hi. I’m kind of a newbie to MFC proramming, but I’ve been doing OpenGL for a while now. I am making a program called Particle Studio, which shows a particle cluster in the view window, and provides a series of dialogs for the user to edit the attributes of the particles.

Everything works fine except that after it’s been running for a while it sometimes freezes. The freezes are not caused by my particle code, because the particle code is taken directly from my main engine (which uses SDL), and there are no freezes in that.

The program is an SDI program, and I use the view window to issue OpenGL commands. I update my scene and redraw it when the OnIdle function of the app is called. In the PreCreateWindow function for the view, I specify the following class styles:

AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_OWNDC, AfxGetApp()->LoadStandardCursor(IDC_ARROW), NULL,NULL);

I set up OpenGL as follows:

int CParticleStudioView::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;

// TODO: Add your specialized creation code here
static HGLRC hRC = NULL;
static HDC hDC = NULL;

hDC = ::GetDC(m_hWnd);

hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);



return 0;


SetDCPixelFormat is a function I wrote that picks the best pixel format.

Any ideas what is causing the freezing?

[This message has been edited by ioquan (edited 11-18-2002).]

OnIdle processes while the system is idle. something of higher priority is probably causing the slow down. Try a flavor of InvalidateRect() after swapbuffers in OnDraw(). If that doesn’t work bypass the MFC message processing loop with your own message handling loop. See


This may be obvious, but first make sure the OnIdle handler returns non-zero, indicating that you want to receive further idle messages… If this fails, you could use SetTimer to fire an OnTimer() regularly.