Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1123
  • Last Modified:

Topmost window in an application

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.
  • 3
  • 3
1 Solution
HI Hey Have you tried with HWND_TOP only

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
DanyJolyAuthor Commented:
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

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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
DanyJolyAuthor Commented:
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 ?
>>Does anybody know the message given to a window when it >>loses focus ?

Try handling WM_KILLFOCUS /OnKillFocus :-)
DanyJolyAuthor Commented:
Almost forgot this forum, thanks for the help.

Featured Post

Hire Technology Freelancers with Gigs

Work with 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.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now