In this link:
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=2;t=018651
Move to the source code and take a look at the functions killGLWindow and CreateGLWindow.
You should explicitly detach the current rendering context from the thread , destroy it and release the DC.
The best reference is MSDN:
Creating a Rendering Context and Making It Current
The following code sample shows how to create an OpenGL rendering context in response to a WM_CREATE message. Notice that you set up the pixel format before creating the rendering context. Also notice that in this scenario the device context is not released locally; you release it when the window is closed, after making the rendering context not current. For more information, see Deleting a Rendering Context. Finally, notice that you can use local variables for the device context and rendering context handles, because with the wglGetCurrentContext and wglGetCurrentDC functions you can obtain handles to those contexts as needed.
// a window has been created, but is not yet visible
case WM_CREATE:
{
// local variables
HDC hdc ;
HGLRC hglrc ;
// obtain a device context for the window
hdc = GetDC(hWnd);
// set an appropriate pixel format
myPixelFormatSetupFunction(hdc);
// if we can create a rendering context …
if (hglrc = wglCreateContext( hdc ) ) {
// try to make it the thread’s current rendering context
bHaveCurrentRC = wglMakeCurrent(hdc, hglrc) ;
}
// perform miscellaneous other WM_CREATE chores …
}
break ;
Deleting a Rendering Context
The following code sample shows how to delete an OpenGL rendering context when an OpenGL window is closed. It is a continuation of the scenario used in Creating a Rendering Context and Making It Current.
// 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);
}
If you have any problems with your own code, that NeHe code works correctly and you only need to change the DrawGLScene() and initGL() functions.
-Ehsan