Text with Transparent Background


Liberty BASIC's native graphics commands caused printed text to appear in a rectangle of the currently set backcolor. If you want the text to have a transparent background so that it appears to be written directly on the graphics, whether drawn graphics or a bitmap, use SetBkMode as in the following demo. You must first get a DeviceContext for the graphicbox, the use SetBkMode with the _TRANSPARENT flag.

    nomainwin
    WindowWidth=404:WindowHeight=340
    graphicbox #1.gb, 1, 1, 400, 300
    open "SetBkMode" for window as #1
    #1 "trapclose [quit]"
    #1.gb "font arial 18 bold"
    #1.gb "down; fill darkpink"
    #1.gb "backcolor darkgreen; color yellow"
    'get handle of graphicbox
    hGBox = hwnd(#1.gb)


    'get device context handle of graphicbox
    CallDLL #user32, "GetDC",_
        hGBox As ulong,_  'handle of graphicbox
        gDC As ulong      'device context


    CallDLL #gdi32, "SetBkMode",_
        gDC As ulong,_          'handle of graphicbox
        _TRANSPARENT As long,_  'flag for transparent background
        result As long          'previous bkmode


'    To see the difference, set background mode to opaque
'    by un-remming the following lines
'    CallDLL #gdi32, "SetBkMode",_
'        gDC As ulong,_     'handle of graphicbox
'        _OPAQUE As long,_  'flag for opaque background
'        result As long     'previous bkmode


    'you must free the device context
    callDLL#user32,"ReleaseDC",_
        hGBox As ulong,_    'graphicbox handle
        gDC As ulong,_      'device context
        result As long


    #1.gb "\\  Transparent BkMode"
    #1.gb "\\  No darkgreen behind text."
    #1.gb "flush"
    wait


[quit] close #1:end


Home

Source Code

Utilities

Internet

Games

Graphics

Media Demos

Snippets

DLL's

API Resources

Freeware

LB 4 Companion

Mastering LB 3

LB Workshop

Game Workshop

Links

Index