Windows NativeAlertWindow can be under AlwaysOnTop

I’ve got some native alert windows that I’m popping up that are appearing below some of my windows which are set to be AlwaysOnTop

Since alert windows are used to notify the user of something important, I don’t think it’d be surprising to have them over the top of AlwaysOnTop windows. This would also match the behaviour on MacOS, where alerts appear on top of everything.

If this seems like a reasonable request, it’s a very easy change.

Add the flag MB_TOPMOST when creating the window

juce_win32_Windowing.cpp Line 4177

Should change from:



1 Like

I think the native alert windows on Windows behave a bit differently to the macOS ones in that if you set them to be on top they will be on top of all windows not just your app’s windows, which can be pretty annoying. However, it’s probably more annoying to have a modal alert window stuck behind an alwaysOnTop JUCE window with no way of dismissing it so I’ll add that flag, but only if there are currently any alwaysOnTop windows.


Cheers @ed95
That’s a really good point though, I hadn’t considered that
Is there a way to determine whether any of the windows created as part of your application are the “active” window?

I know you can check whether a single window is active, but I have no idea if there is some kind of list of created windows stored somewhere

Saying this, if you where able to determine that and then you didn’t make your alert topmost when you returned to the application the alert would still be behind any alwaysOnTop windows, so you’d be back to square one…

You can use ComponentPeer::getPeer() for this and then you can check if it has keyboard focus. Something like:

for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
    if (auto* peer = ComponentPeer::getPeer (i))
        if (peer->isFocused())