1

I have a window which i would like to display above everything else. My code is able to successfully force it to be above almost every window, except for other top-most windows. Here is the code I use:

SetWindowPos(getSDLWindow(),HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);

This line is executed every time I click the middle mouse button (I am using a mouse hook to fire it).

Once I start up my program, and middle-click once, from that point on, my window remains above all "regular" windows.

However, all "special windows" seem to be in the same category as my application window, i.e. special windows when focused are displayed above my application window. In this category of special windows are the taskbar (which using the start menu also seems to activate), right-click menus (even when spawned by regular windows), the Task Manager, and I am sure many others. In fact I am fairly sure any other window which is "topmost" will behave this way. It seems that through my SetWindowPos call I have elevated the status of my application window to a topmost window.

What's neat is that I can start the Task Manager, move it over my app window (so that it is now covering it) and then middle-click inside the Task Manager, and now my app window pops back up in front (while focus remains on the Task Manager). This is nice but I'd like to take it one step further so that my window will be on top no matter what.

Are there any methods to accomplish this other than repeatedly firing SetWindowPos in a loop? I'd like to avoid that if at all possible.

Steven Lu
  • 41,389
  • 58
  • 210
  • 364
  • 7
    Don't do that. Your users will hate you. – Mark B Sep 15 '11 at 17:04
  • Well, there'll be big signs and a giant checkbox letting users turn it off... I'll figure something out. You know, I actually intend on tracking the mouse and moving (and resizing) my app window **out of the way** of the cursor. I just want it there to display important information. – Steven Lu Sep 15 '11 at 17:08
  • You want there to be a way in which pop-up windows from porn/gambling/lawyer/virus sites can become absolute topmost with no access to the task manager? Even if you find a way to do what you want, M$ will block it off as soon as they can rush out a 'Critical Security' update, and rightly so! – Martin James Sep 15 '11 at 17:08
  • 1
    I'm pretty sure Raymond Chen (the Old New Thing) had a blog post about this recently. Basically it boils down to: you can't. If you could top other topmost windows, there's nothing stopping another program from topping you. Then you're right back where you started. – Michael Kristofik Sep 15 '11 at 17:09
  • 1
    What if [two programs did this](http://blogs.msdn.com/b/oldnewthing/archive/2005/06/07/426294.aspx) (Old New Thing link)? – Alan Stokes Sep 15 '11 at 17:09
  • @Alan That's a pretty funny situation being illustrated there. – Steven Lu Sep 15 '11 at 17:12

1 Answers1

8

No, because There is no "super topmost" flag.

Nor should you because all the super-top-most windows will fight each other for control.

John Dibling
  • 99,718
  • 31
  • 186
  • 324
  • Damn, beat me to it. I was going to post the exact same links :) +1. – R. Martinho Fernandes Sep 15 '11 at 17:15
  • 6
    I love this quote: "This is like saying, 'Sometimes I'm in a hurry, and I want to make sure I am the next person to get served at the deli counter. To do this, I find whoever has the lowest number, knock them unconscious, and steal their ticket. But sometimes somebody else comes in who's also in a hurry. That person knocks me unconscious and steals my ticket. My plan is to set my watch alarm to wake me up periodically, and each time it wakes me up, I find the person with the lowest number, knock them unconscious, and steal their ticket. Is there a better way?'" Okay, point taken. :) – Steven Lu Sep 15 '11 at 17:17
  • it's useful when you want to capture sceen of some topmost windows – Wang Mar 27 '22 at 06:38