Set ALL window's Z-Order

I have my app set to be on top with regards to the Z-order, by using the following code in the app’s open event handler:

Declare Function NSClassFromString Lib "Cocoa" ( inName As CFStringRef ) As Ptr
Declare Function sharedApplication Lib "Cocoa" selector "sharedApplication" ( classRef As Ptr ) As Ptr
Dim myApp As Ptr =  sharedApplication( NSClassFromString( "NSApplication" ) )
Declare Sub activateIgnoringOtherApps Lib "Cocoa" selector "activateIgnoringOtherApps:" ( appRef As Ptr, flag As Boolean )
activateIgnoringOtherApps( myApp, True )

However, when I launch other windows from my app - they appear underneath any windows from other apps which I may have on screen.

Is there any way to set ALL of my app’s windows to be on top of any other app’s windows?

Do I need to add code to each of the window’s open events? If so, what code?

Thank you all in advance.

(macOS 11)

Richard! Glad to see you back mate!

Are your windows that you are opening set for Document type or another type?

The easiest way would be to put a method in the app class (or a module) with the window as the parameter:

Sub SetWindowsOnTop(w as Window)
//your code here
End Sub

And then a single line of code in the open event of every window:

app.SetWindowOnTop self

If you tell a window to stay in front, the OS won’t make it automatically for every other window; it’s just like a property of an object (setting one doesn’t change the same property of other similar objects).

Thanks Arnaud, I will try that later.