Is top level-window or not ?

How can I know if a window handle is associated to a top-level window or not ?
mike_marquetAsked:
Who is Participating?
 
jfhuangConnect With a Mentor Commented:

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
 
ScottyDawgCommented:
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
 
ZoppoCommented:
Hi mike_marquet,

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

ZOPPO
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
mike_marquetAuthor 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.
0
 
WynCommented:
Zoppo,top-level window is not topmost window.
0
 
ZoppoCommented:
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
 
mikeblasCommented:
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
 
mikeblasCommented:
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
 
mike_marquetAuthor 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.
0
 
ZoppoCommented:
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
 
vgopaljiCommented:
Hi mike_marquet,
 To get top-level window use
  GetWindow(GW_HWNDFIRST).
..vgopalji
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.