Drawing GDI object on OpenGL makes them flicker!

I have an OPENGL window and when I draw GDI text and line on top of the window using the CClientDC device context, the text and line flickers alot. I have already tried Double buffering but it didnt help. Is there any way I can draw GDI object on the screen without causing flickering. Can I get access to the OpenGL back buffer?

Following is the code I am using to draw the line:

if( m_curr_pDC == NULL)
{
InvalidateRect(NULL);
m_curr_pDC = new CClientDC(this);
OnPrepareDC(m_curr_pDC);
}

// Variable for the window size
RECT window_size;

// Get the window size
GetClientRect(&window_size);

// Create a back buffer
CClientDC back_pDC(NULL);
back_pDC.CreateCompatibleDC(m_curr_pDC);

// Create a bitmap for back buffer
CBitmap back_bm;

back_bm.CreateCompatibleBitmap(m_curr_pDC,
window_size.right, window_size.bottom );

// Select the bitmap in the back buffer
back_pDC.SelectObject(&back_bm);

// Copy the screen to the back buffer
back_pDC.BitBlt(0,0, window_size.right, window_size.bottom, m_curr_pDC, 0,0, SRCCOPY);

// Now Draw the line in the back buffer
int old_op;

CPen *old_pen = back_pDC.SelectObject(&pen);

back_pDC.MoveTo(dw_pts[0].x,dw_pts[0].y);

if( flag )
{
old_op = back_pDC.SetROP2(R2_XORPEN);
}

back_pDC.PolylineTo((POINT *)(&dw_pts[1]),cnt - 1);

// Copy the back buffer to the screen
m_curr_pDC->BitBlt(0,0, window_size.right, window_size.bottom, &back_pDC, 0,0, SRCCOPY);

// Select the old pen back
back_pDC.SelectObject(&old_pen);

if( flag )
{
back_pDC.SetROP2(old_op);
}

back_pDC.SelectObject(old_pen);

// Delete the Back buffer and its BMP
back_bm.DeleteObject();
back_pDC.DeleteDC();

[This message has been edited by flare (edited 12-04-2003).]

First, make sure your WM_ERASEBKGND event handler returns nonzero to keep the defautl window handler from clearing the window, your OpenGL code does that.
GDI doesn’t know anything about OpenGL backbuffers, you can get no direct access.
You can get access to the back buffer contents by glReadPixels, but then you have access to the OpenGL anyway and shouldn’t use GDI to draw a line, use OpenGL only.
If you want to do that on a window somebody else rendered with OpenGL or with code you have no access to, you cannot fix the flicker. Just draw the GDI line directly into the frontbuffer then, much quicker than your method.

So you mean that if I want to remove the flicker I will have to draw the lines and text in OpenGL. I cannot have any use of SwapBuffers() and the opengl Back buffer?

Actually, all the remaining output is done in OpenGL but the text and lines are drawn in GDI… All the drawing is done before the GDI calls. After the GDI calls I call glDrawBuffer( GL_BACK ) and then glFlush().