Windows SDK: What is a child window?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: Windows SDK: What is a child window?

Hybrid View

  1. #1
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,023

    Windows SDK: What is a child window?

    Q: What is a child window?

    A: A child window is a window with WS_CHILD style set and has the following properties:
    • it has a parent window;
    • stays always in the parent's client area (cannot be displayed outside);
    • if the parent is moved, the child window is moved in the same way (its position relative to parent's client area doesn't change);
    • it is destroyed when its parent is destroyed.

    Notes
    • to create a child window we have to set WS_CHILD style and pass a handle to the parent window in the call of CreateWindow or CreateWindowEx functions;
      Example
      Code:
      // create a child window
      HWND hWndChild = CreateWindow(_T("BUTTON"), _T("Push"),
                                    WS_VISIBLE|WS_BORDER|WS_CHILD, // WS_CHILD style is set
                                    5, 6, 80, 30,
                                    hWndParent,                    // parent window handle
                                   (HMENU)1999, hInstance, NULL);
    • Generally, the child window position is given relative to the parent's client area.
      In the example above, 5 and 6 are x, and y coordinates relative to top-left corner of parent's client area.
      Other examples
      Code:
      // moves a child window
      MoveWindow(hWndChild, 
                 98, 99, // coordinates relative to parent client area
                 80, 30, TRUE);
      Code:
      // moves a child window
      SetWindowPos(hWndChild, NULL, 
                   98, 99, // coordinates relative to parent client area 
                   0, 0, SWP_NOSIZE|SWP_NOZORDER);
    • MDI child frame windows have set an additional extended stye: WS_EX_MDICHILD.
    • WS_CHILDWINDOW and WS_CHILD are synonyms;
    • generally, controls (buttons, list boxes, etc) are child windows;
    • all windows with no WS_CHILD style are top-level windows;
    • do not confuse child with owned windows; anthough an owned window has a parent (better said, an owner), it has no WS_CHILD style.
    Last edited by ovidiucucu; January 25th, 2010 at 04:03 AM.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center