Always on top problem

I have a button in my DialogWindow derived class and I want it to toggle the always on top mode for my window. so I do this:

setAlwaysOnTop( !isAlwaysOnTop() );

First click it becomes on top but on second click he stays on top and I cannot stop making it on top. I looked at the code and debugged it and got here:

void NativeDesktopWindow::setAlwaysOnTop (bool isOnTop)
{
SetWindowPos ((HWND)nativeHandle,
(isOnTop) ? HWND_TOPMOST : HWND_TOP,
0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}

everything looks ok, first time isOnTop is true, second time its false but the window stays on top

any idea why?

thanks

I tried to do something simpler with the Juce demo and got the same problem:

MainDemoWindow::MainDemoWindow()
: DialogWindow (T(“JUCE Demo!”),
Colours::lavender,
false)
{
setVisible (true);
setResizeable (true); // resizability is a property of DialogWindow

// sets the main content component for the window to be this tabbed 
// panel. This will be deleted when the window is deleted.
setContentComponent (new ContentComp());
setAlwaysOnTop( true );
setAlwaysOnTop( false );

}

the Juce demo window stays on top…maybe the problem is related to the DropShadowers or some other components that are becoming on top?

interesting… I’ll have a play with that. Might be some win32 quirk that needs a workaround.

ok, looks like a typo - I think HWND_TOP should be HWND_NOTOPMOST instead.

thanks, that solved the problem…I looked at the Win32 docs and for some reason thought it was ok

One minor doc issues: NativeDesktopWindow::setAlwaysOnTop does not apear in the HTML documentation

One more problem, if I click my always on top button on and off, the main window shadows remain on top until I switch to to my app again and then to another window using atl-tab, maybe I should repaint the window to prevent this?

ah yes, the shadows should follow the always-on-topness. If you can hack it for now, I’ll sort that out for the next release.