[WinAPI] Ce este o fereastra "top-level"?

Folosire Windows API in programe C/C++ (forum moderat)
Post Reply
User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3776
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

[WinAPI] Ce este o fereastra "top-level"?

Post by Ovidiu Cucu » 31 Jan 2010, 14:08

Q: Ce este o fereastra top-level?

A: Top-level sunt toate ferestrele care nu sunt child (copil); altfel spus nu au setat stilul WS_CHILD.

Note
  • spre deosebire de ferestrele copil, o fereastra top-level poate fi afisata oriunde pe ecran;
  • multe definitii spun ca o fereastra top-level este "o fereastra care nu are parent (parinte)";
    este corect dar aceasta poate da nastere la o confuzie: multi cred ca orice fereastra care a fost creata pasand un handle valid in argumentul hWndParent al functiei CreateWindow(Ex) "are un parinte" deci, conform cu definitia, nu este o fereastra top-level;
    de fapt, hWndParent poate fi sau un handle la fereastra parinte sau un handle la fereastra owner;
    daca hWndParent este un handle valid la o fereastra iar stilul WS_CHILD nu este setat, avem o fereastra top-level "owned";
  • o fereastra top-level poate fi sau nu owned dar niciodata child; putem spune ca poate avea un owner dar nu poate avea niciodata un parent;
  • ferestrele top-level pot fi overlapped sau pop-up;
  • in functiile CreateWindow(Ex), MoveWindow, SetWindowPos etc, cordonatele sunt relative la ecran (screen coordinates);


Exemple

Code: Select all

// 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: Select all

// 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);
Vezi si
<< Back to Windows API Index



Post Reply