Replacing old declare with WindowPtr

Found an old declare in Kaju where Xojo tells me that the WindowPtr is deprecated:

[code]Declare Sub SendBehind Lib “Carbon” (window as WindowPtr, behindWindow as WindowPtr)

If App.WindowCount > 0 then
app.Window(0).Show

For i as Integer = 1 to App.WindowCount - 1
SendBehind App.Window(i), App.Window(i - 1)
Next
End if[/code]

What do I need to use instead? If there is a function in the MBS plugin I’d rather use that.

That would be NSWindow.orderWindow:relativeTo.

Untested, but it should be something close:

Declare sub OrderWindow Lib "AppKit" selector "orderWindow:relativeTo:" (winHandle as Integer, OrderMode As Integer, OtherWindowNumber As Integer)
OrderMode is an enumeration with the values
Out = 0
Above = 1
Below = -1

And the WindowNumber can be retrieved by

Declare Function getWindowNumber Lib "AppKit" selector "windowNumber" (winHandle As Integer) As Integer

Or you can pass a 0 for “Each window on this level”.

Alternatively, there is also the orderBack and orderFront(regardless) methods if you don’t need a window comparison.

P.S.: Should also be part of MBS.

Thanks, Ulrich, I was looking only for SendBehind in the MBS docs. With OrderBack I found the correct page in the documentation.

Is OrderBack the one I need?

Unfortunately, my new codes crashes so hard that I don’t even get a crash log:

If App.WindowCount > 0 then Window(0).Show For i as Integer = 1 to App.WindowCount - 1 app.Window(i).NSWindowMBS.orderBack Next End if

Yes, I guess it should be fine, and I am surprised (let’s say clueless) about the crash. Catalina? Invisible or hidden windows? (should not crash anyway).
Did you check what window the code tries to move back?
OrderRelative does not seem to be part of MBS. Did you try the declare instead?

EDIT: Stupid idea, but did you try to invert the loop – window count -1 downto 1?

Of course, Crapolina.

I actually had to check what “move to front does”. I think that OrderFront is better. That doesn’t crash at least. But if I have 2 windows open then the code closes the second window. Inverting the loop doesn’t make a change.

I’ll make an example and ask Christian what I’m doing wrong.

Check the console; as the crash information may be logged there.

Calling window.show should bring it to the front of the queue anyway.

I am surprised that it obviously doesn’t for you, hence the workaround.

And as for your crashes; it’s changing the order of the windows as it goes through to move them back. If you need to use this workaround grab the windows into an array and from that array send them back.

The correct code is:

[code]If App.WindowCount > 0 then
Window(0).Show

For i as Integer = 1 to App.WindowCount - 1
app.Window(i).NSWindowMBS.orderFront
Next
End if[/code]

I just need to fix the problems I have in my window menu. Additionally, I did some copy-pasta bug. So it’s good that I had a look at that part of the code.

Always a good idea to de-noodle your code from time to time. :smiley: