简体   繁体   English

确定HWND是否代表顶级窗口的最佳方法是什么?

[英]What's the best way do determine if an HWND represents a top-level window?

Is it to check for the WS_CHILD bit: 是检查WS_CHILD位:

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

Or is there a better way? 或者,还有更好的方法?

Assume : Straight C calling only existing Windows API code. 假设 :Straight C只调用现有的Windows API代码。

  • Way #1: Test hWnd==GetAncestor(hWnd,GA_ROOT) 方式#1:测试hWnd==GetAncestor(hWnd,GA_ROOT)

  • Way #2: Use IsTopLevelWindow (user32 Win7, undocumented) 方式#2:使用IsTopLevelWindow (user32 Win7,未记录)

GetParent()API返回当前窗口的父级或所有者。

Your method is possible (But I think you had better to check if it is a overlapped/popup window too). 你的方法是可行的(但我认为最好还是检查它是否是一个重叠/弹出窗口)。 There is maybe another way -- That is to enum all top level windows and to check if your windows is included in result. 可能还有另一种方法 - 即枚举所有顶级窗口并检查您的窗口是否包含在结果中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM