Solved

Is top level-window or not ?

Posted on 2000-02-17
11
387 Views
Last Modified: 2013-11-20
How can I know if a window handle is associated to a top-level window or not ?
0
Comment
Question by:mike_marquet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 1

Expert Comment

by:ScottyDawg
ID: 2530941
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...
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2531065
Hi mike_marquet,

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

ZOPPO
0
 

Author Comment

by:mike_marquet
ID: 2531129
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:Wyn
ID: 2531130
Zoppo,top-level window is not topmost window.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2531209
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
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 2533422
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
0
 
LVL 11

Expert Comment

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

..B ekiM
0
 

Author Comment

by:mike_marquet
ID: 2533894
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.
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2534230
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
0
 

Expert Comment

by:vgopalji
ID: 2534368
Hi mike_marquet,
 To get top-level window use
  GetWindow(GW_HWNDFIRST).
..vgopalji
0
 

Accepted Solution

by:
jfhuang earned 30 total points
ID: 2575639

How about the program code below?


bool isTopWindow(CWnd *pWnd)
{
      CWnd *pWndParent = pWnd->GetParent();
      CWnd *pWndChild  = pWndParent->GetWindow(GW_CHILD);
      pWndChild = pWndChild->GetWindow(GW_HWNFIRST);
      if (pWndChild == pWnd) return true;
      else return false;
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question