Child windows - OpenGL

This is a discussion on Child windows - OpenGL within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to make my own low poly modeller with OpenGL and I need to have 1 or more child ...

Child windows - OpenGL

I'm trying to make my own low poly modeller with OpenGL and I need to have 1 or more child windows (the viewports). Below is what I have so far (which is not working at all, ie: no child window is displayed).:

I've used child windows before in the form of buttons, listboxes, etc. but never just a plain child window.

My intention is to have a seperate HDC and HGLRC to go with each window.

I'm pretty sure it just has something to do with me being clueless as to how to create a regular child window, but I've searched MSDN, Google and the boards and all that I've found was stuff relevant to controls (buttons, edits, etc) and MFC.

Check the return value from RegisterClassEx, if it's non-zero the problem lies with wnd creation, if it's zero the problem is with window registration. Use GetLastError immediately after the failed function call. While GetLastError usually returns something reasonable under win2k (and presumably xp) I find it's not too reliable with win98.

Perhaps the g_hWnd is NULL/not initialised. For example, if you are setting this (presumably) global variable as the return value of CreateWindow(Ex) for the parent window it will not be valid during processing of WM_CREATE,WM_NCCREATE messages ie those sent during processing of CreateWindow(Ex).

Try using the hwnd sent to your parent wndproc in the WM_CREATE handler; you can also initialise the global window handle there too.

Hope that is of some use to you.

edit:

>>I feel like a dummy for missing the WS_VISIBLE flag and not checking the return values! <<

Did you create a parent window first? According to my Win32
Programmers Ref :

If you specify the WS_CHILD style in CreateWindowEx but do not specify a parent window, Windows does not create the window.

Also, my OpenGL ref says you have to use WS_CLIPSIBLINGS |
WS_CLIPCHILDREN when you CreateWindowEX. I haven't tried it without
doing that, so I don't exactly know why that would be, but it looks like
the parent window will draw over the child in OpenGL , therefore not show it,
if you don't use those window styles.

Thanks a ton guys! I've got it working (in the sense that I can create a child window and attach it's own HDC to it). What I needed to do was use the WS_CLIP* styles for the windows, NOT forget the WS_VISIBLE for the child windows (duh! ) and create the child windows inside my WinMain right after I create my parent window.

I always thought that WM_CREATE was called after your main parent window was created. It pays to actually know the right info.

globalerr_h, what OpenGL ref. book do you have? So far I've just been learning from tutorials, etc. on the web but I'd love to have a hands on reference. I've seen a handful on Amazon but I wanted to get some feedback before I buy one.

RedBook is widely available on the web. Just Google it up.
BlueBook, or Programmers' Reference, is proprietary, and you have to
pay for it. As far as I know. Hard copy new costs around $75 US. Well
worth it, if you're into OGL. IMHO.

"hMenu
[in] Handle to a menu, or specifies a child-window identifier depending on the window style. For an overlapped or pop-up window, hMenu identifies the menu to be used with the window; it can be NULL if the class menu is to be used. For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window. "

So you should only be able to create one.

Your code is setting them all to 0.

May I suggest a STRUCTURE to hold the ID's, HWND's, HDC's, system objects and dimensions of the child windows.

A loop can then be used to create and later 'clean up' all your allocated / created resources at main window open / close.