- JanetTerra JanetTerra

Transparent Window

This demo creates a window of varying degrees of transparency. Thanks to John Richardson for the code contained with LB Window Spier, a Libby Contest entry, 2004. The function for obtaining the OS Version was obtained at Alyce's Restaurant found at URL http://www.alycesrestaurant.com/osversion.htm


    Nomainwin
 
    WindowWidth = 600
    WindowHeight = 400
    UpperLeftX = int((DisplayWidth-WindowWidth)/2)
    UpperLeftY = int((DisplayHeight-WindowHeight)/2)
    text$ = "Translucence here is initially set at 200. Try " + _
        "setting to higher and lower numbers for desired " + _
        "transparency. 0 will make your window complete " + _
        "transparent. 255 is the maximum. This code was " + _
        "taken from the Libby contest entry, LB Window Spier" + _
        ", by John Richardson. This demo will NOT work on " + _
        "Windows 98 or Windows 95."
    Statictext #transp.txt1, text$, 20, 20, 550, 200
    Statictext #transp.txt2, "", 20, 250, 550, 100
 
    Open "Transparent Window" for Window as #transp
    #transp, "Trapclose EndDemo"
 
    hTransp = hWnd(#transp)
    #transp, "Font Verdana 12 Bold"
    If OSVersionFlag() Then
        Call TransparentWindow hTransp, 200
        #transp.txt2, "Success!"
    Else
        #transp.txt2, "This demo will NOT work on Windows 98 " + _
            "or Windows 95"
    End If
    Wait
 
Sub EndDemo handle$
    Close #transp
    End
End Sub
 
Sub TransparentWindow handle, translucence
    CallDLL #user32, "SetWindowLongA", _
        handle as Ulong, _
        -20 as Long, _
        524544 as Long, _
        layer as Long
    CallDLL #user32, "SetLayeredWindowAttributes", _
        handle as Ulong, _
        0 as Long, _
        translucence as Long, _
        2 as Long, _
        layer as Long
End Sub
 
Function OSVersionFlag()
    struct OSVERSIONINFO, _
        dwOSVersionInfoSize as Long, _
        dwMajorVersion as Long, _
        dwMinorVersion as Long, _
        dwBuildNumber as Long, _
        dwPlatformId as Long, _
        szCSDVersion as Char[128]
    L = Len(OSVERSIONINFO.struct)
    OSVERSIONINFO.dwOSVersionInfoSize.struct = L
    CallDLL #kernel32, "GetVersionExA", _
        OSVERSIONINFO as struct, _
        result as Boolean
    MajorVer = OSVERSIONINFO.dwMajorVersion.struct
    If MajorVer < 5 Then
        OSVersionFlag = 0
    Else
        OSVersionFlag = 1
    End If
End Function


For more coding tricks with transparent windows, see Fun with Transparent Windows at the Liberty BASIC Programmer's Encyclopedia Wiki site. - JanetTerra JanetTerra Aug 4, 2006