Page 1 of 1
Transparent Layered Window -Opaque Title Bar?
Posted: Fri Apr 13, 2018 10:41 pm
by IdeasVacuum
Transparent window, the title bar is also transparent:
Code: Select all
#Win = 0
iFlags.i = #PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_Invisible|#PB_Window_SystemMenu
If OpenWindow(#Win, 50, 50, 200, 200, "Transparent", iFlags)
SetWindowColor(#Win, RGB(100,080,200))
SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
HideWindow(#Win, #False)
StickyWindow(#Win, #True)
EndIf
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Is there a way to set the title bar Opaque?
Re: Transparent Layered Window -Opaque Title Bar?
Posted: Mon Apr 16, 2018 3:06 pm
by RSBasic
Do you mean like this?
Code: Select all
EnableExplicit
If OpenWindow(0, 0, 0, 500, 400, "Window", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
SetWindowColor(0, RGB(255, 0, 0))
SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(0), RGB(255, 0, 0), 0, #LWA_COLORKEY)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf
Re: Transparent Layered Window -Opaque Title Bar?
Posted: Tue Apr 17, 2018 6:58 am
by RASHAD
Maybe
Code: Select all
#Win = 0
#Win1 = 1
Procedure WindowProc(hWnd,uMsg,wParam,lParam)
Result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_SIZE,#WM_MOVE
ResizeWindow(#Win1,WindowX(#Win,#PB_Window_InnerCoordinate), WindowY(#Win,#PB_Window_InnerCoordinate),WindowWidth(#Win),WindowHeight(#Win))
Case #WM_NCACTIVATE
Result = 1
EndSelect
ProcedureReturn Result
EndProcedure
iFlags.i = #PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_SizeGadget
If OpenWindow(#Win, 50, 50, 200, 200, "Transparent", iFlags)
SetWindowColor(#Win, RGB(100,080,200))
SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(#Win), RGB(100,080,200), 0, #LWA_COLORKEY)
StickyWindow(#Win, #True)
OpenWindow(#Win1, WindowX(#Win,#PB_Window_InnerCoordinate), WindowY(#Win,#PB_Window_InnerCoordinate), 200, 200, "", #PB_Window_BorderLess,WindowID(#Win))
SetWindowColor(#Win1, RGB(100,080,200))
SetWindowLongPtr_(WindowID(#Win1), #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(#Win1), 0, 100, #LWA_ALPHA)
EndIf
SetActiveWindow(#Win)
SetWindowCallback(@WindowProc())
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Transparent Layered Window -Opaque Title Bar?
Posted: Wed Apr 18, 2018 11:58 pm
by IdeasVacuum
Hi RSBasic
Not really, because with COLORKEY it's all or nothing, you can't control the % of transparency or colour as you can with LWA_ALPHA.
Take a look at Rashad's solution - one to add to your WinAPI Library?
Re: Transparent Layered Window -Opaque Title Bar?
Posted: Thu Apr 19, 2018 12:02 am
by IdeasVacuum
Hi Rashad
That is a seriously clever idea, works perfectly!
Re: Transparent Layered Window -Opaque Title Bar?
Posted: Fri Oct 25, 2019 8:14 am
by BarryG
How do we remove this later:
Code: Select all
SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
For when we don't want the window to be transparent anymore?
Re: Transparent Layered Window -Opaque Title Bar?
Posted: Fri Oct 25, 2019 1:41 pm
by Demivec
BarryG wrote:For when we don't want the window to be transparent anymore?
Code: Select all
; Add WS_EX_LAYERED to window styles
SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)
;set transparency
SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
; Remove WS_EX_LAYERED from this window styles
SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE) & ~#WS_EX_LAYERED)
; Ask the window And its children To repaint
RedrawWindow_(WindowID(#Win), #Null, #Null, #RDW_ERASE | #RDW_INVALIDATE | #RDW_FRAME | #RDW_ALLCHILDREN)
@Edit: You can also reset the alpha level back to full but that won't free any memory that's been reserved to process the alpha.
Re: Transparent Layered Window -Opaque Title Bar?
Posted: Fri Oct 25, 2019 3:47 pm
by RASHAD
Hi BarryG
Code: Select all
#Win = 0
iFlags.i = #PB_Window_Tool|#PB_Window_ScreenCentered|#PB_Window_SystemMenu
If OpenWindow(#Win, 50, 50, 200, 200, "Transparent", iFlags)
ButtonGadget(0,10,170,60,24,"Change")
SetWindowColor(#Win, RGB(100,080,200))
SetWindowLongPtr_(WindowID(#Win), #GWL_EXSTYLE, #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
StickyWindow(#Win, #True)
EndIf
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Quit = 1
Case #PB_Event_Gadget
Select EventGadget()
Case 0
run ! 1
If run = 1
SetLayeredWindowAttributes_(WindowID(#Win), 0, 255, #LWA_ALPHA)
Else
SetLayeredWindowAttributes_(WindowID(#Win), 0, 100, #LWA_ALPHA)
EndIf
EndSelect
EndSelect
Until Quit = 1