Clickthrough overlay

Windows specific forum
k10k10
New User
New User
Posts: 3
Joined: Sat Apr 28, 2018 4:23 pm

Clickthrough overlay

Post by k10k10 »

Has anyone actually managed to create a clickthrough overlay yet?
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Clickthrough overlay

Post by chi »

depends...

just a guess

Code: Select all

OpenWindow(0, 0, 0, 320, 200, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(0, 10, 10, 300, 30, "depends...")

SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TRANSPARENT)
SetLayeredWindowAttributes_(WindowID(0), 0, 150, #LWA_ALPHA)

StickyWindow(0, 1)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
Et cetera is my worst enemy
k10k10
New User
New User
Posts: 3
Joined: Sat Apr 28, 2018 4:23 pm

Re: Clickthrough overlay

Post by k10k10 »

kinda like this, except that you should be able to use the drawing functions in an efficient way (like in a screen)
and you can still see the window borders (& it is not fully transparent),

I am basically talking about something that you can use as a fullscreen overlay
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Clickthrough overlay

Post by chi »

k10k10 wrote:I am basically talking about something that you can use as a fullscreen overlay
Using another window as overlay only works as long as your program is not a fullscreen game (DirectX, OpenGL, ...)
For everything else you could use a maximized borderless window drawn with UpdateLayeredWindow (#WS_EX_LAYERED) and made click-through with #WS_EX_TRANSPARENT
Et cetera is my worst enemy
k10k10
New User
New User
Posts: 3
Joined: Sat Apr 28, 2018 4:23 pm

Re: Clickthrough overlay

Post by k10k10 »

Yeah, the game would obviously also run in a windowed mode.
Could you provide a little example?

Code: Select all

InitSprite()
OpenWindow(0, 10, 10, 200, 200, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered | #PB_Window_BorderLess | #PB_Window_Tool)
OpenWindowedScreen(WindowID(0), 0, 0, 200, 200)

SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE)|#WS_EX_LAYERED|#WS_EX_TRANSPARENT)
SetLayeredWindowAttributes_(WindowID(0), 0, 55, #LWA_ALPHA)

StickyWindow(0, 1)

While WaitWindowEvent() <> #PB_Event_CloseWindow 
  StartDrawing(WindowOutput(0))
    Circle(100, 100, 5, RGB(0, 255, 0))
  StopDrawing()
Wend
(didnt maximize it yet, but thats easy)

The main problem I would have with this code is, that I can not make the window itself fully transparent, without also making the things drawn on it transparent!

(Also on win10 borderless doesnt work the same way it did on win7 and when making the window fully transparent, it is not sticky on top anymore)
User avatar
chi
Addict
Addict
Posts: 1034
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Clickthrough overlay

Post by chi »

k10k10 wrote:Could you provide a little example?
not really
k10k10 wrote:The main problem I would have with this code is, that I can not make the window itself fully transparent, without also making the things drawn on it transparent!
UpdateLayeredWindow wont work with PB's sprite engine. You have to create a 32bit image (rgba(0,0,0,0)) and draw on it (needs premultiplied alpha) and send it to UpdateLayeredWindow to render the window... Not as simple to code as it sounds ;)
Et cetera is my worst enemy
Post Reply