Jump to content
  • Advertisement
Sign in to follow this  
Cornstalks

Problem with Windows and Parents

This topic is 4279 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say I have the following code:
HWND parent;
HWND child;
HINSTANCE hInst;
 
WNDCLASS wc = { CS_OWNDC | CS_DBLCLKS,
                wndProc,
                0,
                0,
                hInst,
                LoadIcon(NULL, IDI_APPLICATION),
                LoadCursor(NULL, IDC_ARROW),
                (HBRUSH)GetStockObject(BLACK_BRUSH),
                NULL, // menu
                "Class Name" };
 
parent = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
                         "Class Name",
                         "Parent Window",
                         WS_OVERLAPPEDWINDOW,
                         0,
                         0,
                         512,
                         512,
                         NULL, // No Parent
                         NULL,
                         hInst,
                         NULL);
 
child = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
                        "Class Name",
                        "Child Window",
                        WS_OVERLAPPEDWINDOW,
                        0,
                        0,
                        512,
                        512,
                        parent, // Has a parent
                        NULL,
                        hInst,
                        NULL);

The program runs and the parent window is created, and then the child window. The child window is always above the parent in the z-order, and if I close the parent, the child closes. This is exactly what I want, however if I were to create both windows without a parent and then use the SetParent function, like this:
HWND parent;
HWND child;
HINSTANCE hInst;
 
WNDCLASS wc = { CS_OWNDC | CS_DBLCLKS,
                wndProc,
                0,
                0,
                hInst,
                LoadIcon(NULL, IDI_APPLICATION),
                LoadCursor(NULL, IDC_ARROW),
                (HBRUSH)GetStockObject(BLACK_BRUSH),
                NULL, // menu
                "Class Name" };
 
parent = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
                         "Class Name",
                         "Parent Window",
                         WS_OVERLAPPEDWINDOW,
                         0,
                         0,
                         512,
                         512,
                         NULL, // No Parent
                         NULL,
                         hInst,
                         NULL);
 
child = CreateWindowEx( WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
                        "Class Name",
                        "Child Window",
                        WS_OVERLAPPEDWINDOW,
                        0,
                        0,
                        512,
                        512,
                        NULL, // No Parent *********
                        NULL,
                        hInst,
                        NULL);
 
SetParent(child, parent);

With the new code the child is now inside of the parent window, which is not what I want. Likewise, if I were to do SetParent(child, NULL) in the first set of code, it doesn't appear that anything has been done. Also, if I called the function GetParent(child) in the first set of code, it returns NULL. Why is this and is there any way to use SetParent to have the parent and child windows behave like they do in the first set of code? [C++, Win32]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!