Window Opacity - WindowExtensions

On this topic I asked a modification of the Module WindowExtensions . It was oh but doesn’t work again since Xojo 2021r3, as I explained in this topic with another declare, the Xojo debugbuild hangs without any break in Xojo, so it was not easy to know where the problem was.

Xojo told me, after I update the code to new API2, in the Method Opacity of WindowExtensions it doesn’t accept Ptr but need Integer.
SetAlphaValue( wind.Handle, value )
I added .Integer :
SetAlphaValue( wind.Handle.Integer, value )
But as I said above, when I build the debugbuild it hangs or it crash.

Another question: Is there a way to send a notification to a person on a specific topi?
I would like to notify @Ulrich Bogun . As I sometimes see a name after an @ , I try to write his name after a @ .

You need to change the first parameter of the declare to a Ptr.

Declare Sub SetAlphaValue Lib "Cocoa" selector "setAlphaValue:" ( windowRef As Ptr, alphaValue As CGFloat)

Then supply Window.Handle as that parameter value without converting to an Integer.

SetAlphaValue( self.Handle, 0.25 )

Thank you very much Anthony. I have another problem, I draw things directly on the window and since I update to DesktopWindow it doesn’t draw anything and it hangs, I have to stop my debugbuild. I would have prefer to have a Xojo bug indicated what’s wrong. I will investigate.
But you resolve my problem I couldn’t investigate in as I don’t know anything in Declare. Thank you again.

Happy to help. Please don’t forget to mark the solution so that others who encounter this issue can quickly find it in the future.

1 Like

If I may make a suggestion, add the class name and the framework to the declare. This way, when anyone needs to look up the reference documentation, they already know which framework and which class the documentation is under.

Otherwise doing a search for setAlphaValue will reveal multiple hits, and may give the wrong impression about the API status.

Declare Sub NSWindow_setAlphaValue Lib "AppKit" selector "setAlphaValue:" ( NSWindowInstance As Ptr, alphaValue As CGFloat )

Edit: like wise with the property names, especially when dealing with different classes in a declare.

Sam, I used the module as it, as I downloaded in the other topic. As I wrote, I don’t know declare. It was writtel Soft before the Declare and you didn’t write it. Maybe I search long time ago what Soft means but I forget. And it is written Lib “Cocoa” and you write Lib “AppKit” . When I read that, I thought it was the name of the MacOS X system framework we use, but you use a different one?

I found my problem, I wrote Self.Refresh instead of Self.Invalidate in previous window but now it is DesktopWindow then I have to write Self.Refresh**(True)** .

Then it explain why it doesn’t draw as I draw a rectangle in a MouseDrag event (size change when mouse move). But instead of simply doesn’t draw as mouse move and draw when I release the mouse, the application hangs. it doesn’t refresh the buttons of my window, if I open another window it display a blank window, it doesn’t display all the controls in the window.
It is typically the kind of bug I hesitate to report as it is very strange.
It is a simple program and I can give the code if you want to have a look.

I wanted to add one more things, usually Xojo change the instruction’s name when there are changes.
Priore ro API2 : Canvas.Refresh(False) was Refresh now but without redraw background.
Now with API2, it means Refresh after as was Invalidate .

AFAIK: Because I don’t work for Xojo so I can’t double check their code, “soft” declare means that framework is NOT loaded when the application launches. This allows an application to be able to dynamically load different frameworks on demand. IIRC all Cocoa declares are soft.

Cocoa is the Umbrella framework that all the other frameworks sit under. Xojo engineers have mentioned to me that explicitly using the name of the actual framework (and not the umbrella framework) are faster, I assume because they directly link to the Framework responsible for that API.

The reason I make these suggestions is because the Ohanaware App Kit is based upon declares, there are over 3,000 declares in OAK and it is important to be able to look up the correct documentation sometimes, especially as Apple deprecate so much of their existing APIs. It is also helpful to know which version of the OS supported what API, especially since Apple moved to annual releases, sometimes APIs only exist for one version of the OS! So by making these few changes to the declare, you will help yourself in the future and others that you share it with.

2 Likes

Thank you very much Sam.
For those who wants, here a download link. It contains my personals functions shared between my programs and WindowExtensions to set the opacity of a window.

1 Like

I think the code of Anthony and Sam should be pasted in the open event of your window.
Try with a new Xojo project and past the code into its open event. It should work.

Soft Declare Sub setAlphaValue Lib “AppKit” selector “setAlphaValue:” ( windowRef As Integer, alphaValue As CGFloat )

setAlphaValue( self.Handle, 0.25 )

It works, I have a slider in another window which set the opacity of the window.

I did not get any notification, or none I noticed. But I found the thread by chance now.