I’m new to the JUCE framework, but I have ran into the same problem as well.
It’s a very annoying problem when doing standalone application development, but the fix might be very easy to implement… at least on Windows.
The reason this is not working out of the box is that JUCE does not have the ability to set the owner of a window. If you use the addToDesktop function it forces the window style to a WS_CHILD. This makes the window to be only visible into his parent as you will now have a Parent → Child relation. This is good for a lot of stuff, but not if you want to have “floating” windows (known as tool/popup windows in Windows).
To force a Owner->Window relation you need to have the WS_POPUP style. JUCE will set this style but doensn’t allow to set the owner without it modifying this style flag. You can force this on Windows using this method:
ShellWindow::ShellWindow(const juce::String& title, int requiredButtons, juce::ComponentPeer *Owner)
: DocumentWindow(title, juce::LookAndFeel::getDefaultLookAndFeel().findColour(DefaultWindowBackgroundColorId), requiredButtons, true)
{
setUsingNativeTitleBar(false);
setResizable(true, false);
if (auto Peer = getPeer())
{
auto Handle = (HWND) Peer->getNativeHandle();
::SetWindowLongPtr(Handle, GWLP_HWNDPARENT, (LONG_PTR)Owner->getNativeHandle());
}
}
(Sorry if there are obvious mistakes in the code, I’m just a hobby programmer)
This will set the owner of the newly created windows, effectively creating floating windows. Windows will take care of all the Z-ordering automatically.
It will also work with native titlebars, however Windows will only allow the close button (which makes sense).
In order NOT to have a taskbar icon/entry for this floating window, you can do this:
int ShellWindow::getDesktopWindowStyleFlags() const
{
int styleFlags = DocumentWindow::getDesktopWindowStyleFlags();
return styleFlags & ~juce::ComponentPeer::windowAppearsOnTaskbar;
}
You need to strip the windowsAppearsOnTaskbar flag, which gets automatically set by the TopLevelWindow class.
Now all of this has only be tested in my small scale app I’m developing, so there could be a lot of things that might go wrong in large scal apps.