Topmost window in an application

Posted on 2003-03-16
Medium Priority
Last Modified: 2013-11-20
I know there is an other thread on a similar subject, but my question has a variant.

Il would like to know how to place a dialog window on top of all the other windows and dialogs of an application, but not on top of windows of any other application. The goal is to make a toolbox that would be topmost, but if an other application get the focus, the toolbox will not get over it.

I currently tried many ways to do this without success :

   // Placed in the Create() function of the toolbox dialog
   // This make the window topmost of ALL the other windows on the desktop
   // regardless of the application it belongs to.

  // Placed in the parent window

The second way works well if the parent window is a CView window, but it doesn't work when the parent window s a DoModal() dialog.
Question by:DanyJoly
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
  • 3

Expert Comment

ID: 8148037
HI Hey Have you tried with HWND_TOP only


Expert Comment

ID: 8152374
Dear DanyJoly ,
*try as AmitAgarwal suggested to you

>>but it doesn't work when the parent window s a DoModal() >>dialog.
* try to create a MODELESS dialog box

Author Comment

ID: 8157384
The HWND_TOP is not exactly the behavior I want. My first message was not clear enough. I would like my dialog to be the topmost window of my application and to stay topmost even when an other window of my application gets the focus. But I dont want this dialog to interfere with the other applications.

With the HWND_TOP flag, the dialog gets topmost, but it wont stay over the other windows if I click an other window.

With  SetWindowPos(&wndTopMost,... and the HWND_TOPMOST flag, the dialog has the appropriate behavior, but it has it "too good" : it will be on top even of the other applications window!

Sorry for the lack of clarity
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!


Expert Comment

ID: 8159073
Ok try this API (or its MFC equivalent with CWnd )

The BringWindowToTop function brings the specified window to the top of the Z order. If the window is a top-level window, it is activated. If the window is a child window, the top-level parent window associated with the child window is activated.

BOOL BringWindowToTop(
  HWND hWnd   // handle to window

Author Comment

ID: 8166843
Hi FrenchFries, BringWindowToTop effectively brings my window to the top, but it won't necessarily make it stay there. Maybe combined with a function called when the window lose focus. Does anybody know the message given to a window when it loses focus ?

Accepted Solution

FrenchFries earned 225 total points
ID: 8167248
>>Does anybody know the message given to a window when it >>loses focus ?

Try handling WM_KILLFOCUS /OnKillFocus :-)

Author Comment

ID: 8590713
Almost forgot this forum, thanks for the help.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

765 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