Solved

Is top level-window or not ?

Posted on 2000-02-17
11
366 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
  • 3
  • 2
  • 2
  • +4
11 Comments
 
LVL 1

Expert Comment

by:ScottyDawg
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
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
 
LVL 5

Expert Comment

by:Wyn
Comment Utility
Zoppo,top-level window is not topmost window.
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
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
Comment Utility
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
Comment Utility
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 30

Expert Comment

by:Zoppo
Comment Utility
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
Comment Utility
Hi mike_marquet,
 To get top-level window use
  GetWindow(GW_HWNDFIRST).
..vgopalji
0
 

Accepted Solution

by:
jfhuang earned 30 total points
Comment Utility

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iSeries DB2 Query 2 83
mapAB Challlenge 35 84
Detect file exist or not 3 76
Not needed 13 53
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now