Can I make the Plan Box window stay above all other windows?

Re-download the project. But the window does stay topmost? Is that not what you’re seeing when you try?

I don’t need to re-download I already fixed the button action to show/hide window2 and it works as it should, but when I copy paste this exact code into a new window in my project and set a button just like your example it doesn’t work… any idea what can interfere with that?

The window you create in your existing project, does it have a Super of Window or something else?
Do you have any other declares in your project?
Does your code have a WindowProc callback?

Here you have one of my projects, you can try using it and see:
https://www.dropbox.com/s/hi8jq7q0b31yb98/ProResER_v2.0.05%20Beta036.xojo_binary_project.zip?dl=1

I assume you are you on about the AppInfo window?

You have all sorts of code playing with that window, including Me.Hide in the AppInfo.Deactivate event which will cause it to vanish when you click on anything else in windows to try and move it over the top to test the topmost code you’re trying to implement.

No no, don’t try it on this window, create a new one

Just for that feature, you might as well just make the content of the AppInfo window in a Container on Window1, then show/hide the container on Window1, then you wont have to play around with manipulating window positions/order to try and keep it visible when moving another window.

Oh ok, one sec

Yeah, you’ve just fallen foul of a Xojo 64bit windows bug that I’ve reported and Xojo doesn’t seem to want to make public, even though I have requested it to be made public.

This is the declare you need, not the one from above, I don’t know where that declare came from but it won’t work in 64bit and it does work in 32bit, which is where I was testing it. As your project is 64bit, it was showing the issue.

Declare Function SetWindowPos Lib "User32.dll" (hWnd As Integer, hWndInsertAfter As Integer, X As Int32, Y As Int32, cx As Int32, cy As Int32, uFlags As UInt32) As Int32

Hope it helps.

1 Like

Thank you from the bottom of my heart @anon20074439
I highly appreciate the effort and the time you put on this, bless you!

All the best,
Sagi

You are welcome Sagi, glad we got to the bottom of it :slight_smile:

Also, free bug report :slight_smile:

If C:\Users\Julian\AppData\Roaming\AudioSpot
doesn’t exist, your app NOE’s on the line after // “Load setting from file //” in Window1.Open

You’ll need to check each step along the path to make sure the folder exists as you go along the path to make sure you can look for the file.

Wow! thanks, I’m out of words;)

The following code (updated with @anon20074439 's Declare) works OK here building 64bit with Xojo2019r1.1 and r.2.1 for Windows 10 (and Mac) and using Document window-frame.
But I do not know about 64bit with newer releases of Xojo since I do not have them.

#if TargetMacOS
Const NSNormalWindowLevel = 0
Const NSFloatingWindowLevel = 3
Const NSModalPanelWindowLevel = 8
Const NSDockWindowLevel = 20
Const NSMainMenuWindowLevel = 24
Const NSPopUpMenuWindowLevel = 101
Const NSScreenSaverWindowLevel = 1001

declare sub NSWindowSetLevel lib “Cocoa” selector “setLevel:” (WindowRef as integer, Level as Integer)
if Value then
NSWindowSetLevel w.Handle, NSFloatingWindowLevel
else
NSWindowSetLevel w.Handle, NSNormalWindowLevel
end if

#else
Declare Function SetWindowPos Lib “User32.dll” (hWnd As Integer, hWndInsertAfter As Integer, X As Int32, Y As Int32, cx As Int32, cy As Int32, uFlags As UInt32) As Int32

Const HWND_BOTTOM = 1
Const HWND_NOTOPMOST = -2
Const HWND_TOP = 0
Const HWND_TOPMOST = -1

Call SetWindowPos(w.Handle, HWND_TOPMOST, w.left, w.top, w.Width,w.Height,0)
#endif

Yes it does @Carlo_Rubini, great stuff!

If you already have MBS Plugin Complete License:

In the open event of a Window:

#If TargetWindows Then
  Me.WinTopMostWindowMBS = True     // on top of all Windows.
#EndIf
1 Like

To summarize and thank you all for everything I learned here;)
All been tested just now on both macOS and Win10 64-bit, note the extra optional parameters I added for more in-depth use cases plus detailed flags meaning.

Public Sub TopMost(extends wt as Window, assigns Value as Boolean)

#if TargetCocoa then
  Const NSNormalWindowLevel = 0
  Const NSFloatingWindowLevel = 3
  Const NSModalPanelWindowLevel = 8
  Const NSDockWindowLevel = 20
  Const NSMainMenuWindowLevel = 24
  Const NSPopUpMenuWindowLevel = 101
  Const NSScreenSaverWindowLevel = 1001
  
  Declare Sub NSWindowSetLevel lib "Cocoa" selector "setLevel:" (WindowRef as integer, Level as Integer)
  if Value then
    NSWindowSetLevel wt.Handle, NSFloatingWindowLevel
  else
    NSWindowSetLevel wt.Handle, NSNormalWindowLevel
  end if
#elseif TargetWindows Then
  Declare Function SetWindowPos Lib "User32.dll" (hWnd As Integer, hWndInsertAfter As Integer, X As Int32, Y As Int32, cx As Int32, cy As Int32, uFlags As UInt32) As Int32
  
  Const HWND_BOTTOM = 1  // Places the window at the bottom of the Z order.
  Const HWND_NOTOPMOST = -2  // Places the window above all non-topmost windows (that is, behind all topmost windows). no effect if the window is already a non-topmost.
  Const HWND_TOP = 0  // Places the window at the top of the Z order.
  Const HWND_TOPMOST = -1  // Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.
  
  // the combination of those are the value of the last parameter of the argument.
  'const SWP_NOSIZE = 1  // Retains the current size (ignores the cx and cy parameters).
  'const SWP_NOMOVE = 2  // Retains the current position (ignores X and Y parameters).
  'const SWP_NOZORDER = 4  // Retains the current Z order (ignores the hWndInsertAfter parameter).
  'const SWP_NOREDRAW = 8  // Does not redraw changes. If this flag is set, no repainting of any kind occurs. (applies to the client area)
  'const SWP_NOACTIVATE = 10  // Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter)
  'const SWP_SHOWWINDOW = 40 // Displays the window.
  'const SWP_HIDEWINDOW = 80  // Hides the window.
  'const SWP_NOOWNERZORDER = 200  // Does not change the owner window's position in the Z order.
  
  // in this example I used both SWP_NOSIZE + SWP_NOMOVE = 3
  If Value Then
    Call SetWindowPos(wt.Handle, HWND_TOPMOST, wt.left, wt.top, wt.Width, wt.Height, 3)
  Else
    Call SetWindowPos(wt.Handle, HWND_NOTOPMOST, wt.left, wt.top, wt.Width, wt.Height,0)
  End If
#endif

End Sub

To use this anywhere in your code simply write:
aWindow.TopMost=True
Or to turn it off:
aWindow.TopMost=False


Now I have one simple question, will it work on a MessageDialog modal under Windows?
Of course this is unnecessary in macOS as it already has the .ShowModalWithin

1 Like

Hi Gagi_Gal,
Cannot download…

Error (404)

We can’t find the page you’re looking for.

Sorry, it had a nasty bug that @anon20074439 pulled my attention to.
Here is the fixed version:
https://www.dropbox.com/s/uo4zxi1t8r8k7xh/ProResER_v2.0.05%20Beta037.xojo_binary_project.zip?dl=1

Out of curiosity, what is this bug about? (so I can avoid falling into it)

Looking back on it with fresh eyes, the error was simply that Int32 was used instead of Integer in the declare so when it was compiled into 64bit, passing -1 (HWND_TOPMOST) in the Int32 wasn’t correct as -1 in an Int32 vs an Integer are vastly different internally so it wasn’t related to the bug I thought it was.