We help IT Professionals succeed at work.

Is top level-window or not ?

mike_marquet
mike_marquet asked
on
456 Views
Last Modified: 2013-11-20
How can I know if a window handle is associated to a top-level window or not ?
Comment
Watch Question

You could check for the WS_CHILD style or perhaps...

// From a cwnd derived class
CWnd* pWnd = GetDesktopWindow();
ASSERT(pWnd);

while ((pWnd = pWnd->GetNextWindow()) && pWnd->GetSafeHwnd() != hwndToFind); // this may loop around so careful...

bool bTopLevel = pWnd->GetSafeHwnd() == hwndToFind;

Might work, although there's probably an easier way...
CERTIFIED EXPERT

Commented:
Hi mike_marquet,

Try checking it for WS_EX_TOPMOST extended style set ... but this works not for i.e. TaskBar ...

ZOPPO

Author

Commented:
No, what I want to do, is to know if a control is a top-level window.
For example a group control is a top-level window
for all the controls inside the group.

WS_EX_TOPMOST works only for applications I sink.
Wyn

Commented:
Zoppo,top-level window is not topmost window.
CERTIFIED EXPERT

Commented:
sorry, misunderstood your question ...

then perhaps try GetWindow() with GW_HWNDNEXT: For none-child windows result must be not NULL when given window is a top-level window, for child windows the next sibling window of a given window ...

>For example a group control is a top-level window
>for all the controls inside the group.

I do not understand this ... AFAIK a group control is a child window of the dialog as any other controls are, you can only decide its z-order.

ZOPPO

Commented:
mike_marquet, I think you're using a very unstandard derinition of "top-level window" in this question.  What do you _really_ want to know about the window in question?

..B ekiM

Commented:
Maybe, for instance, you want to know if it delimits a group of other controls. Then, you should look for WS_GROUP.

..B ekiM

Author

Commented:
What I want to do, is a window handle picker for all windows or controls like the window finder from Spy++. But I have problems when I have a groupbox inside an other groupbox.
I can get all handle of all controls inside the first groupbox but all handle of all controls inside my second groupbox are not retrieved. When the mouse go over the second groupbox, I get only the groupbox handle.

See also question 'Problem using ChildWindowFromPoint !', in MFC topic area, for some codes.
CERTIFIED EXPERT

Commented:
Now, I tried it and even spy doesn't find the inner group box when it lies beyond the outer one. The only way I can imagine is to get the ChildWindowFromPoint and the for this window get all sibling windows beyond with GetWindow( GW_HWNDNEXT ) and test if the given point is inside its rect.

ZOPPO

Commented:
Hi mike_marquet,
 To get top-level window use
  GetWindow(GW_HWNDFIRST).
..vgopalji
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.