Thread: Child windows - OpenGL

  1. #1
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065

    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).:

    Code:
    case WM_CREATE:
    {		
      WNDCLASSEX wcx;
      wcx.cbSize=sizeof(WNDCLASSEX);
      wcx.style=CS_OWNDC | CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
      wcx.lpfnWndProc=MsgHndlr; 
      wcx.cbClsExtra=0;
      wcx.cbWndExtra=0;
      wcx.hInstance=g_hInst;
      wcx.hIcon=NULL;
      wcx.hCursor=NULL;
      wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
      wcx.lpszMenuName=NULL;
      wcx.lpszClassName="Mini";
      wcx.hIconSm=NULL;
      RegisterClassEx(&wcx);
       g_hChild=CreateWindowEx(WS_EX_CLIENTEDGE,"Mini","",WS_CHILD,20,20,80,80,g_hWnd,NULL,g_hInst,NULL);
       return(0);
    }break;
    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.

    Thanks in advance for any help.

    Jason

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Try giving it the WS_VISIBLE style or use ShowWindow. Failing that:

    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.

  3. #3
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Ken, thanks for the input. Now I now where the problem is (creation) I just need to figure out why. ???

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

    The error # is 1406 which is ERROR_TLW_WITH_WSCHILD (which I'm currently purusing MSDN for some details... )

    thanks again!

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Just a suggestion:

    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! <<

    I know what you mean - I 'forget' all the time!

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    10
    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.

    Hope this helps.
    globalerr_h
    Win98se
    Dev-C++ 4
    Borland55 with JFE

  6. #6
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    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.

    Thanks again guys!

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    10
    For the "redbook", try these:

    www.cs.huji.ac.il/support/docs/OpenGL/ [URL]

    Oops, only managed to copy the one. The redbook is mostly programming
    examples. Mostly the versions I see are written in C++, either Borland or VC++.

    [disclaimer]I haven't been able to find a downloadable bluebook,
    but any bookstore can order it, or Amazon.[/disclaimer]

    Oh, "Redbook" is OpenGL Programmers' Guide.
    "BlueBook" is OpenGL Programmers' Reference.

    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.
    globalerr_h
    Win98se
    Dev-C++ 4
    Borland55 with JFE

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If you use the WS_CHILD (which you do not have too)

    Don't forget to cast the

    HMENU param

    of the CreateWindowEx()

    as the childs int ID resource.

    MSDN
    "HMENU hMenu, // menu handle or child identifier"

    "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.
    Last edited by novacain; 11-18-2002 at 03:07 AM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  2. openGL text in multiple windows
    By hannibar in forum Windows Programming
    Replies: 1
    Last Post: 03-02-2006, 02:17 PM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  4. FlashWindowEx not declared?
    By Aidman in forum Windows Programming
    Replies: 3
    Last Post: 05-17-2003, 02:58 AM
  5. OpenGL and Windows
    By sean345 in forum Game Programming
    Replies: 5
    Last Post: 06-24-2002, 10:14 PM