Solved

Is top level-window or not ?

Posted on 2000-02-17
11
377 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
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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Tab names are off by one 5 54
sumNumber challenge 16 122
format the code in java 6 93
zeroFront challenge 7 96
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

808 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