OpenGL in a child window. No MFC.

Hi guys…tell me what Im doing wrong, Im trying to render a child window with OGL, but having problems…let me post some code.
I create the parent and child window like:

// PARENT
hwnd = CreateWindow (szAppName, szAppName, WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_OVERLAPPED ,
0, 0, 800, 600, NULL, NULL,hInstance, NULL);

// CHILD
oglViewHwnd = CreateWindow (“ChildOne”, “ChildOne”, WS_CHILD | WS_VISIBLE, 100, 100,
200, 200, hwnd , NULL,hInstance, NULL);

Now, my ‘init’ function works like:

HDC hdc = GetDC(m_Hwnd);

SetDCPixelFormat(hdc);

m_Hrc = wglCreateContext(hdc);
wglMakeCurrent(hdc, m_Hrc);

Reshape();	// Resize the window for first time

ReleaseDC(m_Hwnd,hdc);

Any special reason for this to not work?

Thx.

By the way, the same code, if I use the parent window handler, works in the parent…I just cant get to work in the child one.

There’s a couple of things you don’t show that could also be the source of the problem.

  1. Your RegisterClass call. Did you set the style of the WNDCLASS to include CS_OWNDC? You can get some weirdness with OpenGL if you don’t do that.

  2. I’m assuming you just do the standard stuff in SetDCPixelFormat, but it wouldn’t hurt to post that code. The problem could be in there somewhere.

BTW, you don’t need to explicitly call Resize. When a window is first created it is sent a WM_SIZE message right away.

Ok, solved, my problem was I was not using the window handle from the WM_CREATE message.

I’m having exactly the same problem you
describe - could you explain slightly more
about how you overcame your problem?

All my problem was I was using the window handle returned by the CreateWindow function and not the one from the WndProc. Try that instead, if you still have some problems I can post the relevant code of my app.