wglMakeCurrent for multiple windows in MFC

This is a dialog-based application. The dialog holds 2 windows of the same class CWndT with nID=0 and nID=1;
The class CWnd has data member m_hDC, m_hRC to hold its device context and rendering context. I did an experiment as follows.
In the render() of one window (nID=0), I call the render() of another window (nID=1) where I call wglMakeCurrent();
What I expect is that a red line will be draw on the window with nID=1 (I thought that by the time the program reaches the line #1, the render context is associated to the m_hDC and m_hRC of the window with nID=1). But nothing is draw in both window. Why?
The problem can be fixed by uncommenting the line #1. Are there any good ways to make sure that gl functions always draw to the correct window? It seems to me a difficult problem considering the situation that a function may call another function(e.g. MessageBox) which change the flow of control(for example, the control is go to the message handler of another window which call the wglMakeCurrent). I guess there should be a good way to do that.

The segment of code is as follows.
void CWndT::render(void)
if(m_hRC != NULL){
wglMakeCurrent(m_hDC, m_hRC);
if(nID==1) glColor3f(1.0f,0.0f,0.0f);
//wglMakeCurrent(m_hDC, m_hRC); //#1

I’m no MFC expert, but this may be of help to you…


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.