setting a window as NSWindow

Hello,
using MacOSlibrary I can add a “NSWindow” property to a window to set it as a NSWindow, then in the window’s open event handler I can add this code:

nsw = New NSWindow(self) nsw.AnimationBehavior = NSWindow.NSWindowAnimationBehavior.NSWindowAnimationBehaviorDocumentWindow // Zoom in slowely as if opening a document nsw.MovableByBackground = true

Now, I would like to do the same without using macOSLibrary or plugings. Although I’m not versed in declares, I tried several ways to do it, but without achieving any workable solution.
For instance, I first added in the window the following property:

[code]Public Property MovableByBackground as Boolean
Get
#if TargetCocoa
declare function IsMovableByWindowBackground lib CocoaLib selector “isMovableByWindowBackground” ( id As Ptr ) As Boolean
return IsMovableByWindowBackground( self )
#endif
End Get

Set
#if TargetCocoa
declare sub SetMovableByWindowBackground lib CocoaLib selector “setMovableByWindowBackground:” ( id As Ptr, value As Boolean )
SetMovableByWindowBackground( self, value )
#endif
End Set
End Property[/code]

then, in the open event of the window I added:

Soft Declare Function objc_getClass lib "libobjc.dylib" (name As CString) As Ptr Soft Declare Function sel_registerName lib "libobjc.dylib" (name As CString) As Ptr Soft Declare Function RespondsToSelector Lib "Cocoa" selector "respondsToSelector:" (target As Ptr, Sel As Ptr) As Boolean Dim nsWindowClass As Ptr = objc_getClass("NSWindow") self.MovableByBackground = true

But, as I feared, it doesn’t work.

Can anybody help me out? Thanks.

window.handle will get you a NSWindow.instanceID as an integer, wrap that in a Ptr to pass it to the above declares.
https://documentation.xojo.com/api/deprecated/window.html#window-handle

… and you don’t need the first declares in the open event. The last line is enough.
To make Sam’s advice a bit more verbose: Change the calling lines of the property to something like

return IsMovableByWindowBackground(ptr(self.handle))

@Sam Rowlands [quote]window.handle will get you a NSWindow.instanceID as an integer, wrap that in a Ptr to pass it to the above declares.[/quote]

Never used handles by myself, so in the docs I saw that using handles you automatically get a NSWindow: nice to know.
Then it came to my mind that in Xojo example folders I had once seen a declare example, and sure enough, moving according to those example’s code I came up with the following lines that seem to work OK:

[code]Soft Declare Sub center Lib “Cocoa” selector “center” (windowRef As Integer)
declare sub SetMovableByWindowBackground lib “Cocoa” selector “setMovableByWindowBackground:” ( windowRef As integer, value As Boolean )
declare sub setAnimationBehavior lib “Cocoa” selector “setAnimationBehavior:” (windowRef as integer, behavior as NSWindowAnimationBehavior)

center(Self.handle)
SetMovableByWindowBackground(self.Handle, true)
setAnimationBehavior(self.handle, NSWindowAnimationBehavior.NSWindowAnimationBehaviorDocumentWindow)
[/code]

(for setanimationBehavior I had to add the relevant enumeration).

@Ulrich Bogun: Yes, as you see, I removed the opening declares and removed also the MovableByBackground properties.
Should I modify the above code, or leave it as it is?

Thanks for the prompt answers. Much appreciated.

Perfectly fine this way. Integer and Ptr are interchangeable, they basically represent a system-bit sized memory address in this case.

@Urlich Bogun: Thank you for confirming the approch.