What is the best way to determine if an HWND represents a top-level window?

Check the WS_CHILD bit:

LONG style = GetWindowLong(hwnd, GWL_STYLE); int isTopLevel = !(style & WS_CHILD); 

Or is there a better way?

Suppose : direct C, calling only the existing Windows API code.

+6
source share
3 answers
  • Path number 1: Test hWnd==GetAncestor(hWnd,GA_ROOT)

  • Method number 2: use IsTopLevelWindow (user32 Win7, undocumented)

+6
source

Your method is possible (but I think you better check to see if it is too blocked / popup). Perhaps there is another way - to list all the top-level windows and check if your windows are included in the result.

0
source

Source: https://habr.com/ru/post/946735/


All Articles