Borderless window with drop shadow?

Windows specific forum
User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Borderless window with drop shadow?

Post by Samuel »

Does anyone know how to create a borderless window that still keeps the drop shadow?

I'm assuming this has to be done through API which is fine, but my knowledge is pretty limited on this subject.

Any tips or examples well be very much appreciated.
User avatar
STARGÅTE
Addict
Addict
Posts: 2234
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Borderless window with drop shadow?

Post by STARGÅTE »

Code: Select all

Enumeration
	#Window
EndEnumeration

OpenWindow(#Window, 0, 0, 200, 150, "WindowTitle", #PB_Window_BorderLess|#PB_Window_ScreenCentered|#PB_Window_Invisible)
SetClassLongPtr_(WindowID(#Window), #GCL_STYLE, $00020000)
HideWindow(#Window, #False)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
hallodri
Enthusiast
Enthusiast
Posts: 208
Joined: Tue Nov 08, 2005 7:59 am
Location: Germany
Contact:

Re: Borderless window with drop shadow?

Post by hallodri »

Code: Select all

Import ""
	GetProcAddress(hMod, Name.p-ascii)
EndImport

#DWMWA_NCRENDERING_POLICY = 2
#DWMNCRP_ENABLED = 2

Structure Margin
	cxLeftWidth.l
	cxRightWidth.l
	cyTopHeight.l
	cyBottomHeight.l
EndStructure

Procedure DwmSetWindowAttribute(hWnd, attr, attrValue)
	Static hMod
	Static Func
		
	Protected Value.integer\i = attrValue
	
	If Not hMod And Not Func
		hMod = GetModuleHandle_("dwmapi")
		Func = GetProcAddress(hMod, "DwmSetWindowAttribute")
	EndIf
	
	If Func
		ProcedureReturn CallFunctionFast(Func, hWnd, attr, Value, SizeOf(Value))
	EndIf
	
	ProcedureReturn -1
EndProcedure


Procedure DwmExtendFrameIntoClientArea(hWnd, Top, Left, Right, Bottom)
	Static hMod
	Static Func
	
	Protected Margin.Margin	

	Margin\cxLeftWidth = Left	
	Margin\cxRightWidth = Right
	Margin\cyTopHeight = Top
	Margin\cyBottomHeight = Bottom
	
	If Not hMod And Not Func
		hMod = GetModuleHandle_("dwmapi")
		Func = GetProcAddress(hMod, "DwmExtendFrameIntoClientArea")
	EndIf
	
	If Func
		ProcedureReturn CallFunctionFast(Func, hWnd, Margin)
	EndIf	
	
	ProcedureReturn -1
EndProcedure

Procedure Main()
	Protected Window.i
	
	Window = OpenWindow(#PB_Any, 150, 150, 200, 200, "Shadow Test", #PB_Window_BorderLess) 
	
	
	If Window
		
		DwmSetWindowAttribute(WindowID(Window), #DWMWA_NCRENDERING_POLICY, #DWMNCRP_ENABLED)
		DwmExtendFrameIntoClientArea(WindowID(Window), 1, 1, 1, 1)
		
		
		Repeat
		Until WaitWindowEvent() = #PB_Event_CloseWindow	
		
	EndIf
	
	
EndProcedure: End Main()

User avatar
Samuel
Enthusiast
Enthusiast
Posts: 755
Joined: Sun Jul 29, 2012 10:33 pm
Location: United States

Re: Borderless window with drop shadow?

Post by Samuel »

Well, that was quick. :D

Thank you both for the wonderful examples.
HanPBF
Enthusiast
Enthusiast
Posts: 570
Joined: Fri Feb 19, 2010 3:42 am

Re: Borderless window with drop shadow?

Post by HanPBF »

Hello hallodri,

how can the shadow width and form be changed?

thanks!
Post Reply