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

x
  • 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 :

1.
   // Placed in the Create() function of the toolbox dialog
   SetWindowPos(&wndTopMost,60,80,0,0,SWP_NOSIZE);
   // This make the window topmost of ALL the other windows on the desktop
   // regardless of the application it belongs to.

2.
  // Placed in the parent window
  toolbox_dialog->SetWindowPos(this,60,80,0,0,SWP_NOSIZE|WS_EX_TOPMOST);

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

amit
0
 
FrenchFriesCommented:
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
0
 
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

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

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


BringWindowToTop
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
);
0
 
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 ?
0
 
FrenchFriesCommented:
>>Does anybody know the message given to a window when it >>loses focus ?

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

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