Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_OS=#PB_OS_Windows
Procedure SetWindowTranparency(Window, TransparencyColor=#Cyan, Transparency=255)
Protected hWnd=WindowID(window)
;transform into opaque layered window
SetWindowLongPtr_(hWnd, #GWL_EXSTYLE, GetWindowLongPtr_(hWnd, #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(hWnd, TransparencyColor, Transparency, #LWA_COLORKEY | #LWA_ALPHA)
EndProcedure
Procedure SetWindowShadow(Window, IsEnabled=1)
Static *dwmapi
Static *DwmExtendFrameIntoClientArea
Static *DwmSetWindowAttribute
Protected hWnd=WindowID(window)
If Not *dwmapi
*dwmapi=GetModuleHandle_("dwmapi")
If *dwmapi And Not *DwmExtendFrameIntoClientArea And Not *DwmSetWindowAttribute
*DwmExtendFrameIntoClientArea=GetProcAddress_(*dwmapi, Ascii("DwmExtendFrameIntoClientArea"))
*DwmSetWindowAttribute=GetProcAddress_(*dwmapi, Ascii("DwmSetWindowAttribute"))
EndIf
EndIf
If *DwmExtendFrameIntoClientArea And *DwmSetWindowAttribute
CompilerIf Not Defined(DWMNCRP_ENABLED, #PB_Constant) : #DWMNCRP_ENABLED=2 : CompilerEndIf
CompilerIf Not Defined(DWMWA_NCRENDERING_POLICY, #PB_Constant) : #DWMWA_NCRENDERING_POLICY=2 : CompilerEndIf
;enable shadow
Protected value.Integer\i=#DWMNCRP_ENABLED
CallFunctionFast(*DwmSetWindowAttribute, hWnd, #DWMWA_NCRENDERING_POLICY, value, SizeOf(value))
Protected *Margins=AllocateMemory(4*SizeOf(Long))
FillMemory(*Margins, 4*SizeOf(Long), IsEnabled, #PB_Long)
CallFunctionFast(*DwmExtendFrameIntoClientArea, hWnd, *Margins)
EndIf
ProcedureReturn -1
EndProcedure
CompilerEndIf
CompilerIf #PB_Compiler_IsMainFile
; ********************
; EXAMPLE
; ********************
Procedure CreateWindowTest(x, y, parentWindowID=0)
Protected container, Window
Window=OpenWindow(#PB_Any, x, y, 150, 100, "Shadow / Transparency Test", #PB_Window_BorderLess, parentWindowID)
SetWindowColor(Window, #Gray)
container=ContainerGadget(#PB_Any, 5, 5, 50, 50) : CloseGadgetList()
SetGadgetColor(container, #PB_Gadget_BackColor, #Red)
container=ContainerGadget(#PB_Any, 60, 5, 50, 50) : CloseGadgetList()
SetGadgetColor(container, #PB_Gadget_BackColor, #Green)
ProcedureReturn Window
EndProcedure
Procedure Main()
Define FirstWindow=CreateWindowTest(300, 300) ;borderless drop shadow without glow
SetWindowTranparency(FirstWindow, #Cyan)
SetWindowShadow(FirstWindow, 1)
Define FirstWindowID=WindowID(FirstWindow)
Define Window=CreateWindowTest(300, 500, FirstWindowID) ;borderless drop shadow with glow
SetWindowShadow(Window, 1)
Define Window=CreateWindowTest(500, 300, FirstWindowID)
SetWindowTranparency(Window, #Red)
SetWindowShadow(Window, 1)
Define Window=CreateWindowTest(700, 300, FirstWindowID)
SetWindowTranparency(Window, #Green, 100)
SetWindowShadow(Window, 1)
Define Window=CreateWindowTest(700, 500, FirstWindowID)
SetWindowTranparency(Window, #Gray, 100)
SetWindowShadow(Window, 0)
Repeat
Define e=WaitWindowEvent()
If e=#PB_Event_LeftClick
Break
EndIf
Until e=#PB_Event_CloseWindow
EndProcedure
End Main()
CompilerEndIf