Mixing GDI+ and OpenGL, is this a supported method?

It’s 2022 and I’m trying to mix GDI+ with OpenGL on the same screen. I know - sounds crazy!? BUT

I’ve discovered a way to do this, although I’m worried I have discovered an unsupported method or a driver bug; Part of me wonders if I’m close to a simple/correct solution?

Create a window with the following PIXELFORMATDESCRIPTOR flags:


…and yes I’m aware that PFD_SUPPORT_GDI and PFD_DOUBLEBUFFER are not supported together, and yet my solution appears to work (despite very limited testing - I want to run this by you first).

case WM_PAINT:

		RenderOpenGLScene(); // ie. clear screen, draw some stuff, etc.

		hdc = GetDC(hWnd);
			RenderGDIPlusScene(hdc); // Draw some fancy GDI stuff on top of OpenGL.
		ReleaseDC(hWnd, hdc);

		return DefWindowProc(hWnd, uMsg, wParam, lParam);

I realise I have not included any other code, however my application is very simple and my usage of OpenGL is very simplistic. The critical part that appears to make this solution work is the GetDC/ReleaseDC pair instead of BeginPaint()/EndPaint() and the glFinish() command after SwapBuffers(); and calling DefWindowProc() such that the WM_PAINT message gets processed/goes away.

Did you just answer your own question?

That’s interesting, but not something you can depend on. In fact, if you do some websearching, you’ll find some folks that find this doesn’t work on some versions of Windows 10.

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