Make a window transparent

Windows specific forum
AlGonzalez
User
User
Posts: 53
Joined: Sun Feb 15, 2004 6:04 am
Location: Easley, SC, USA

Make a window transparent

Post by AlGonzalez »

Should work on Windows 2000 and above

Code: Select all

#WS_EX_LAYERED = $80000

Procedure SetWindowTransparency(hWnd.l, percent.b)
    Protected alphaLevel.w, p.f
    If percent < 0 Or percent > 100
        ProcedureReturn
    Else
        p.f = percent / 100
        alphaLevel = Int(p * 255)
    EndIf
    
    ; next line sets window to layered extended style
    ; (so we can make it transparent!)
    SetWindowLong_(hWnd, #GWL_EXSTYLE, #WS_EX_LAYERED)

    ; next line sets actual alpha level (can be between 0 and 255,
    ; 255 being fully visible or no transparency)
    SetLayeredWindowAttributes_(hWnd, 0, alphaLevel, 2)
EndProcedure
Last edited by AlGonzalez on Tue Feb 24, 2004 5:59 am, edited 1 time in total.
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

Looks interesting. Will this always fail?

Code: Select all

If percent < 0 And percent > 100
AlGonzalez
User
User
Posts: 53
Joined: Sun Feb 15, 2004 6:04 am
Location: Easley, SC, USA

Post by AlGonzalez »

Dare2 wrote:Looks interesting. Will this always fail?

Code: Select all

If percent < 0 And percent > 100
Oops :oops: that should be an "Or" - I've corrected the above code.

Thanks for the catch.
Post Reply