View Full Version : OpenGL in a child window. No MFC.

07-24-2002, 01:27 PM
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:

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

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);


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

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


Any special reason for this to not work?


07-24-2002, 01:30 PM
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.

07-25-2002, 04:11 AM
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.

07-25-2002, 04:48 AM
Ok, solved, my problem was I was not using the window handle from the WM_CREATE message.

09-21-2002, 02:27 AM
I'm having exactly the same problem you
describe - could you explain slightly more
about how you overcame your problem?

09-21-2002, 02:36 AM
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.