Syncing OpenGL/GDI

I need to do the unthinkable and draw OpenGL commands into a window with GDI (design-time stuff like selection boxes) on top of it. It's working moderately well so far, I just need to get rid of all of the flickering!

Using the ManagedGL class fromhttp://www.opengl.org/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic;f=3;t=014233, I created double-buffered OGL context and overrode the OnPaint event of a Form to perform my drawing commands. A Designer for the Form draws certain GDI objects like snaplines and selection boxes around my OGL objects. As it is now, the OGL canvas does not flicker at all, but the GDI flickers heavily anytime the Form calls OnPaint.

I've noticed removing the SwapBuffers(hdc) call after my OGL commands stops the GDI flicker but clearly the OGL doesn't reander. What I'd like is a double-buffered OGL *and* GDI window where the drawing to the back buffer would be: Draw OGL, Draw GDI over it, swap that buffer.

Has anyone had any experience doing this, or could even offer any insight? I'm a OGL programmer first, and am not quite sure how GDI works with multiple buffers (i.e. does it share the same buffers as the OGL context? Does it's "clear" command also clear the drawn OGL commands? )

Thanks

[1502 byte] By [Quirk] at [2007-12-22]