Windows SDK: What is a top-level 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 top-level window?

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

    Windows SDK: What is a top-level window?

    Q: What is a top-level window?

    A: A top-level window is a window that is not child, i.e. it has not WS_CHILD style set.

    Notes
    • unlike the child windows, a top-level window can be displayed anywhere in the screen;
    • many definitions state that a top-level window is "a window that has no parent";
      that is correct but can lead in a confusion: many people think that every window which is created passing a valid hWndParent in CreateWindow(Ex) "has a parent" then, according to the definition it is not top-level;
      in fact hWndParent may be either a handle to parent or owner window;
      if hWndParent is a valid window handle and WS_CHILD style is not set, then we have a top-level owned window;
    • a top-level window can or can not be owned but is never a child; further we can say that it can have an owner but never has a parent.
    • top-level windows can be either overlapped windows (having WS_OVERLAPPED style and generally used as application main window) or popup windows (having WS_POPUP style, usually temporary windows like message boxes and dialogs);
    • the coordinates used in CreateWindow(Ex), MoveWindow, SetWindowPos, and so on are always scren coordinates (relative to top-left corner of the screen).


    Examples
    Code:
    // create a top-level window (not owned)
    HWND hWnd = CreateWindow(szWindowClass, szTitle, 
                  WS_OVERLAPPED, // WS_CHILD style is not set, so it's a top-level window.
                  CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
                  NULL,          // no handle to the owner, so it's not owned.
                  NULL, hInstance, NULL);
    Code:
    // create a top-level window (owned)
    HWND hWnd = CreateWindow(szWindowClass, szTitle, 
                  WS_OVERLAPPED, // WS_CHILD style is not set, so it's a top-level window
                  CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, 
                  hWndParent,    // handle to the owner, so it's an owned window
                  NULL, hInstance, NULL);
    See also
    Last edited by ovidiucucu; January 25th, 2010 at 06:48 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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center