Page 1 of 1

Make a window transparent

Posted: Tue Feb 24, 2004 5:50 am
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

Posted: Tue Feb 24, 2004 5:57 am
by Dare2
Looks interesting. Will this always fail?

Code: Select all

If percent < 0 And percent > 100

Posted: Tue Feb 24, 2004 6:00 am
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.