Window transparency in Mac Cocoa

Neither of these correctly control the transparency of Mac OS window any longer in Xojo 2021.

Soft Declare Sub SetAlphaValue Lib “Cocoa” selector “setAlphaValue:” ( windowRef As Integer, alphaValue As Single )
SetAlphaValue( wind.Handle, value )

Declare Sub setAlphaValue Lib “Cocoa” Selector “setAlphaValue:” (NSWindow As Ptr, alphaValue As Single)
setAlphaValue(Ptr(wind.Handle), value)

regardless of the value assigned to value, the window disappears. Can anyone provide some assistance. Thank you.

What value(s) have you tried? I bet 0.0 is fully transparent and 1.0 is opaque.

That’s not the Xojo version, it is because you are using 32 Bit code.
Replace Single by Double or CGFloat to keep 32 Bit compatibility.

2 Likes

Thank you. That was the issue, it should be double not single. I should have caught that. It is always good to have another set of eyes look at the code.

2 Likes

Make it easier on yourself in the future.

// --- Mac OS X 10.5 +, values range from 0.0 ~ 1.0
declare sub NSWindow_setAlphaValue Lib “AppKit” selector “setAlphaValue:” ( NSWindowInstance As Integer, value As CGFloat )
NSWindow_setAlphaValue( wind.Handle, value )

This way, the code provides more hints on itself, as you now include the className, the framework, if this API applies to a class instance or the class object, and minimum supported OS Version.

2 Likes