Window transparency on Windows 64 bits


To set window transparency on Windows I used :

// First, check to see if we've set this window up to be layered yet
Const WS_EX_LAYERED = &H80000
Const LWA_ALPHA = 2

if not TestWindowStyleEx( w, WS_EX_LAYERED ) then
  // The window isn't layered, so make it so
  ChangeWindowStyleEx( w, WS_EX_LAYERED, true )

// Now we want to set the transparency of the window.  The values range from 0 (totally
// transparent) to 255 (totally opaque).
Var value as Integer = 255 * alpha

Declare Sub SetLayeredWindowAttributes Lib "user32" ( hwnd As Integer, thecolor As Integer, bAlpha As integer, alpha As Integer )
SetLayeredWindowAttributes( w.Handle.Integer, 0 , value, LWA_ALPHA )

But with app. compiled for 64 bits that causes problems.

How do the same for Windows 64 bits?


Be careful here, this is returning an Integer stored at that location, not the location expressed as an Integer which is what you need.

You will need


or change your declare to use Ptr and don’t bother with the conversion, so you can then just use


Should it not be:

hwnd As Int32

In 64 bit executables, integer is in64.

Var GWL_EXSTYLE As Integer = (-20)
Var WS_EX_RIGHT As Integer = &H1000
Var WS_EX_LEFTSCROLLBAR As Integer = &H4000
Var WS_EX_LAYERED As Integer = &H80000
Var LWA_ALPHA As Integer = &H2
Var LWA_COLORKEY As Integer =&H1

Soft Declare Function SetWindowLong Lib "User32" Alias "SetWindowLongA"(ByVal hwnd As Ptr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
Soft Declare Function SetLayeredWindowAttributes Lib "User32"(windowRef As Ptr, ByVal crKey As Integer, ByVal Alpha As Byte, ByVal dwFlags As Integer) As Boolean

Var style As Integer
style = style Or WS_EX_LAYERED

Call SetWindowLong (self.handle, GWL_EXSTYLE, style)
Call SetLayeredWindowAttributes(self.handle, 0, 150, LWA_ALPHA) 

Adjust as needed

You can see the difference in how the Handle is… handled… between the two blocks of code. It looks like what Julian mentioned.

No, the size of the pointer will change from 32 to 64 depending on the architecture so Integer is correct, but Ptr can also be used.

I’d adjust all those ByVal’s out of there :wink: Intrinsic types are passed byval anyway so its just clutter. Also some of those type are wrong so you might or might not end up with issues down the line.

See Windows APIs to Xojo data type conversion – Samphire's Solace for a lookup table and explanation.


Will do :wink:
But I grabbed from here long time ago

2014, I wasn’t around to correct them :wink: :smiley:


ok but now you have to stay forever! :grin:

1 Like

It’s taking a LOT of restraint to resist a meme response, so many to choose from :slight_smile:


Thanks to all!

Now that works.