How to create a transparent window ?

Hello,

I’m looking for an example on how to create transparent windows (OS X Carbon, OS X Cocoa and Windows). Unfortunately I’m not an expert in using declares, so any suggestion is highly appreciated.

Tobias.

https://forum.xojo.com/4514-round-transparent-window

…plus other hits on a quick search.
Good idea to search the Forums before posting.

Thanks for taking over the search for me. :wink:

Anyway, I have found this example before as well as an older one on the previous RS forums. But I could not find one that works on Windows and maybe someone has written a combined solution.

Good idea to be more polite on a public forum. :slight_smile:

Didn’t mean to imply that you were impolite, Tobias. Maybe inefficient. :slight_smile:
BTW - I have no idea about Windows. I’m not even sure such an animal exists.

Try: https://github.com/macoslib -> WindowsManager.Alpha OS X Carbon, OS X Cocoa only

@Roger Clary : Sorry, it was probably a misunderstanding… not meant offending on my side, too. :slight_smile:

@Joachim Kuno : I’ll have a look at it, too. At first glance, I didn’t find license information. Do you know under which license this library is distributed ?

For the Windows side:

[code]Sub SetWindowAlpha(HWND As Window, Alpha As Single)
’ Alpha is 0.0 (transparent) to 1.0 (opaque)
Declare Function GetWindowLongW Lib “User32” (HWND As Integer, Index As Integer) As Integer
Declare Function SetWindowLongW Lib “User32” (HWND As Integer, Index As Integer, NewLong As Integer) As Integer
Declare Function SetWindowPos Lib “User32” (HWND As Integer, InstertAfter As Integer, X As Integer, Y As Integer, _
Width As Integer, Height As Integer, Flags As Integer) As Boolean
Declare Function SetLayeredWindowAttributes Lib “User32” (hwnd As Integer, hcolor As Integer, bAlpha As Integer, alpha As Integer) As Boolean

Const WS_EX_LAYERED = &h80000
Const GWL_EXSTYLE = -20
Const SWP_NOMOVE = &h2
Const SWP_NOSIZE = &h1
Const SWP_NOZORDER = &h004
Const SWP_FRAMECHANGED = &h20
Const LWA_ALPHA = 2

Dim gwl As Integer = GetWindowLongW(HWND.Handle, GWL_EXSTYLE)
If BitAnd(gwl, WS_EX_LAYERED) <> WS_EX_LAYERED Then
’ convert the window to a layered window if it’s not one already
gwl = gwl Or WS_EX_LAYERED
Call SetWindowLongW(HWND.Handle, GWL_EXSTYLE, gwl)
Call SetWindowPos(HWND.Handle, 0, 0, 0, 0, 0,SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER)
End If

Call SetLayeredWindowAttributes(HWND.Handle, 0, Alpha * 255, LWA_ALPHA)
End Sub
[/code]

macoslib modul About.Notes.License
http://opensource.org/licenses/mit-license.php

I could also suggest the OverlayMBS class in our MBS plugins.

Thank you everybody for your suggestions and hints.

I think I’ll give the solutions using declares a try. I’m not a friend of plugins for such tasks, because I cannot look inside their sources and when programming, it’s important for me to know how things are working. :slight_smile: