I'd like to implement "Always on top" configuration option in my application that takes effect immediately.
I know that I can call Shell constructor with ON_TOP style. Is there a way to do that at runtime, that is after a Shell instance has already been created?
In Cocoa you need to use reflection to get at the Shell instance variable window and then call window.setLevel(OS.NSStatusWindowLevel).
In Carbon you need to get at the shellHandle instance variable and then call OS.SetWindowGroup(shellHandle, OS.kFloatingWindowClass). You might be able to get away with doing just that much, depending on your needs.
In either case, you should also forcibly add the SWT.ON_TOP bit to the style field. Particularly in Carbon, lots of things rely on that bit being set.
On windows, you can do it like this:
private static final void toggleAlwaysOnTop(Shell shell, boolean isOnTop){
long handle = shell.handle;
Point location = shell.getLocation();
Point dimension = shell.getSize();
OS.SetWindowPos(handle, isOnTop ? OS.HWND_TOPMOST : OS.HWND_NOTOPMOST,location.x, location.y, dimension.x, dimension.y, 0);
}
All those api's are public so there is no need for reflection.
The last argument for SetWindowPos is not the same with Shell.getStyle(). Leaving it as 0 currently causing no problem for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With