Sver
Full Member
Posts: 145
|
Post by Sver on Nov 26, 2023 4:07:37 GMT -5
' 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 2" #main.gfb, "setfocus" #main.gfb, "line 0 0 200 200" #main.gfb, "when leftButtonMove draw" 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
|
|
|
Post by Rod on Nov 26, 2023 7:17:56 GMT -5
It might be useful if you included a reference to where these snippets were sourced from. Folks could then explore a bit further.
|
|
|
Post by xxgeek on Nov 26, 2023 10:35:54 GMT -5
That is an odd window.
There is no glass! If you click inside the window, it goes behind what was behind it when you clicked.
So where, or on what, is the red line being drawn?
After increasing the size of the red line to 10 so it could be clicked, clicking the red line does not put the window behind.
Very interesting, never seen that before today.
|
|
|
Post by tsh73 on Nov 26, 2023 14:31:29 GMT -5
Interesting For me Shift F5 produces But via Debug/Light debug it works. I found mention in a help file, on "TroubleShooting" page: I will reboot, just for a case, and report here how it ends... Also if you click (and hold) on that red line you can continue to draw red dots on empty space (taht actually native LB code but to start it you should click somewhere on a window where it will not be intercepted by Windows itself, so borders (resize) anf window title (move) will not do. Ans since everything else is transparent, that leaves red line as only starting point. Drawn points could be used to start another drawing. ) Also minimizing/restoring, or resizing window, kills transparent effect - turns to be ordinary window with white graphicbox !! adding a"flush" make effect stay after resize (if you draw something taht is) Sub draw handle$, x, y #handle$, "set "; x; " "; y ' #handle$, "flush" End Sub !! ( trying to add "flash" before first WAIT make Ctrl F5 open debugger, like in a case of Alt F5 This is definitely weird It looks like we are treading on thin ice, without understanding what's going on, and it could suddenly break...
|
|
|
Post by tsh73 on Nov 26, 2023 14:35:38 GMT -5
It got away without reboot Happens I had JustBASIC window opened Then I close it program in LB started running on Shift F5 Then I run JB again, LB program started barking on Shift F5.
I pretty sure it should not interfere, but indeed it does.
|
|
|
Post by Rod on Nov 26, 2023 15:24:54 GMT -5
While we can create transparent Windows, the idea is to have something opaque on them, thus creating a uniquely shaped (ie non rectangular) visible window. The subject is very well covered in the LBPE. Being able to click through the invisible part of the window is something I would expect to be able to do. Else you might be clicking in vain on a visible control.
'floating "gadget" code nomainwin WindowWidth = 120 WindowHeight = 144
'set window stylebits to layered and stay on top WS.EX.LAYERED = 524288 style=WS.EX.LAYERED or _WS_EX_TOPMOST stylebits #1, 0, 0, style, 0
'set graphicbox stylebits to no border stylebits #1.gb, 0, _WS_BORDER, 0, 0 graphicbox #1.gb, 0,0,120,144
'open popup window open "Clock" for window_popup as #1
'get the window handle hMain = HWND(#1)
'set the window to use red as transparent mask 'red bits of your image won't bee seen 'they will be transparent and allow "shaped" or 'floating graphic windows calldll #user32, "SetLayeredWindowAttributes",_ hMain As long,_ 'window handle 255 As long,_ '255 = Red color key (rgb color value) bAlpha As long,_ '0 = Completely transparent (0-255) 1 As long,_ '1 = use color key for transparency / 2 = use bAlpha ret As long 'nonzero=success
'move window with api call clockx=DisplayWidth-130 clocky=10 calldll #user32, "MoveWindow",_ hMain as ulong, _ 'window handle clockx as long,_ 'x location of window clocky as long,_ 'y location of window 120 as long,_ 'desired width of window 144 as long,_ 'desired height of window 1 as boolean,_ 'repaint flag,0=false,1=true ret as long 'nonzero=success if ret=0 then [quit]
' start event tracking #1 "trapclose [quit]" #1.gb "when leftButtonUp [quit]" #1.gb "when leftButtonMove [movewindow]"
'these are simple drawn graphics, you can do photorealist bmp images to 'draw clock face #1.gb "down ; fill red ; home ; backcolor darkgray ; circlefilled 48 ;color white ; circle 49" for angle = 0 to 330 step 30 #1.gb "up ; home ; north ; turn "; angle #1.gb "go 40 ; down ; go 5" next angle #1.gb "flush"
timer 1000, [display] wait
[display] time$ = time$() hours = val(time$) if hours > 12 then hours = hours - 12 minutes = val(mid$(time$, 4, 2)) seconds = val(right$(time$, 2))
' center the cursor and turtle draw the clock #1.gb "up ; home ; down ; north"
' erase each hand if its position has changed if oldHours <> hours then #1.gb "size 2 ; color darkgray ; turn "; oldHours * 30 + int(oldMinutes/2) ; " ; go 19 ; home ; color black ; north" : oldHours = hours if oldMinutes <> minutes then #1.gb "size 2 ; color darkgray ; turn "; oldMinutes * 6 ; " ; go 38 ; home ; color black ; north" : oldMinutes = minutes if oldSeconds <> seconds then #1.gb "size 1 ; color darkgray ; turn "; oldSeconds * 6 ; " ; go 38 ; home ; color black ; north" : oldSeconds = seconds
' redraw all three hands, second hand first #1.gb "size 1 ; turn "; seconds * 6 ; " ; go 38" #1.gb "size 2 ; home ; north ; turn "; hours * 30 + int(minutes/2); " ; go 19" #1.gb "home ; north ; turn "; minutes * 6 ; " ; go 38" #1.gb "delsegment seg" #1.gb "flush seg" wait
[movewindow] 'this is called when we place the window and whenever it is dragged CallDLL #user32, "ReleaseCapture",r As void CallDLL #user32, "SendMessageA",hMain As ULong,_WM_NCLBUTTONDOWN As ULong,_HTCAPTION As Long,0 As Long,r As Long wait
[quit] timer 0 close #1 end
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Nov 27, 2023 1:55:09 GMT -5
It might be useful if you included a reference to where these snippets were sourced from. Folks could then explore a bit further. I really don't know. I saved things in the past, from different sources into my database. I know, that this last snippet don't work perfect, but people can use parts of it or change it. Nice clock ! When people want normal window transparant: nomainwin
graphicbox #main.1 ,0 ,0 ,800 ,600 open "Test" for window as #main #main "trapclose [quit]"
hwnd1 = hwnd(#main)
call MakeWindowTransparent hwnd1, 150 'between 0 - 255 wait
[quit] close #main:end
sub MakeWindowTransparent hwnd, transparency calldll #user32, "GetWindowLongA", hwnd as ulong, -20 as long,_ r as long x = r or 524288 calldll #user32, "SetWindowLongA", hwnd as ulong, -20 as long,_ x as long, r as long calldll #user32, "SetLayeredWindowAttributes", hwnd as ulong,_ 0 as long, transparency as long, 2 as long, r as long end sub
|
|
Sver
Full Member
Posts: 145
|
Post by Sver on Nov 29, 2023 6:35:03 GMT -5
Rod,
You made a cool example with drawing a clock.
With BMP pictures they only have to chance the background with the color 255 0 0 (red) and it looks like a window-sprite with a red color which isn't visible on the desktop or not on=top window.
Of course some width and height are different.
The whole window or windows can move/locate with
nomainwin open "Hi" for window as #1 #1 "trapclose [quit]" h=hwnd(#1) x=10 y=50 width=500 height=100
calldll #user32, "SetWindowPos",_ h as ulong,_ 'window handle _HWND_TOP as ulong,_ 'position flag x as long,_ 'new left x coord y as long,_ 'new top y coord width as long,_ 'new window width height as long,_ 'new window height _SWP_SHOWWINDOW as long,_ 'SetWindowPos show flag re as boolean
CallDLL #kernel32, "Sleep", 2000 As long, ret As void
x=100 y=50 width=500 height=100
calldll #user32, "SetWindowPos",_ h as ulong,_ 'window handle _HWND_TOP as ulong,_ 'position flag x as long,_ 'new left x coord y as long,_ 'new top y coord width as long,_ 'new window width height as long,_ 'new window height _SWP_SHOWWINDOW as long,_ 'SetWindowPos show flag re as boolean
wait
[quit]close#1:end
|
|