다음 코드 샘플에서는 OpenGL 창이 닫혀 있을 때 OpenGL 렌더링 컨텍스트를 삭제하는 방법을 보여줍니다. 시나리오의 연속으로, 렌더링 컨텍스트 생성 및 현재화 만들기에 사용된 것과 같습니다.
// a window is about to be destroyed
case WM_DESTROY:
{
// local variables
HGLRC hglrc;
HDC hdc ;
// if the thread has a current rendering context ...
if(hglrc = wglGetCurrentContext()) {
// obtain its associated device context
hdc = wglGetCurrentDC() ;
// make the rendering context not current
wglMakeCurrent(NULL, NULL) ;
// release the device context
ReleaseDC (hwnd, hdc) ;
// delete the rendering context
wglDeleteContext(hglrc);
}