Sver
Full Member
Posts: 145
|
Post by Sver on Nov 27, 2023 3:18:59 GMT -5
'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 "Test" for window as #1 #1 "trapclose [quit]" #1.gb "font arial 18 bold" #1.gb "down" #1.gb "fill 200 200 200" ' #1.gb "backcolor darkgreen" #1.gb "color black" 'get handle of graphicbox hGBox = hwnd(#1.gb)
#1.gb "\\ No Transparent text background "
'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 Backgound" #1.gb "flush" wait
[quit] close #1:end
|
|
|
Post by xxgeek on Nov 27, 2023 8:27:02 GMT -5
Another transparent text window 'posted by Sver 'https://libertybasiccom.proboards.com/thread/2466/window-transparant
' Set the Variables WS.EX.LAYERED = 524288 ' WS_EX_LAYERED Unrecognized Windows constant ColorRef = 0 ' ColorRef set to black bAlpha = 255 ' Degree of opacity (0 - 255)ignored in this instance LWA.COLORKEY = 1 ' LWA_COLORKEY Unrecognized Windows constant dwFLAGS = LWA.COLORKEY ' Action is colorRef is transparent color Nomainwin
WindowWidth = 600 WindowHeight = 400
UpperLeftX = int((DisplayWidth-WindowWidth)/2) UpperLeftY = int((DisplayHeight-WindowHeight)/2)
Graphicbox #main.gfb, 0,0,600,400
Stylebits #main, 0, 0, WS.EX.LAYERED, 0 Open "Transparent Window" for window as #main
#main, "Trapclose EndDemo" hMain = hWnd(#main)
Call SetLayeredWindowAttributes, hMain, ColorRef, bAlpha, dwFLAGS #main.gfb, "down ; fill black ; color red" #main.gfb, "size 12" #main.gfb, "setfocus" ' #main.gfb, "line 0 0 200 200" #main.gfb, "place 100 170" #main.gfb, "when leftButtonMove draw" #main.gfb, "font arial 14 bold" #main.gfb "\\Hello World - Goodbye Solid Windows" wait
Sub draw handle$, x, y #handle$, "set "; x; " "; y End Sub
Sub EndDemo handle$ Close #main End End Sub
Sub SetLayeredWindowAttributes hWindow, ColorRef, bAlpha, dwFLAGS CallDLL #user32, "SetLayeredWindowAttributes", _ hWindow as Ulong, _ ColorRef as Long, _ bAlpha as Long, _ dwFLAGS as Long, _ result as Long End Sub
|
|