It is currently Thu Jan 21, 2021 3:38 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [win] Borderless Window : Drop shadow / Transparency
PostPosted: Sat Feb 11, 2017 7:13 pm 
Offline
Addict
Addict
User avatar

Joined: Mon May 26, 2003 3:07 pm
Posts: 1477
Location: Nantes
Code:
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

_________________
Imagewin8.1 x64 5.31 | IDE | PB plugin | Tools | Sprite | JSON | visual tool


Top
 Profile  
Reply with quote  
 Post subject: Re: [win] Borderless Window : Drop shadow / Transparency
PostPosted: Tue Feb 14, 2017 12:17 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jul 08, 2013 8:43 pm
Posts: 257
Very nice! More windows!! :mrgreen:
Thanks for share eddy!

_________________
If translation=Error: reply="Sorry, Im Spanish": Endif


Top
 Profile  
Reply with quote  
 Post subject: Re: [win] Borderless Window : Drop shadow / Transparency
PostPosted: Tue Feb 14, 2017 3:10 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Jan 22, 2009 3:48 am
Posts: 640
Location: china
winxp:
setwindowshadow() is spare
win7:
unknown

_________________
my pb for chinese:
http://ataorj.ys168.com


Top
 Profile  
Reply with quote  
 Post subject: Re: [win] Borderless Window : Drop shadow / Transparency
PostPosted: Tue Feb 14, 2017 4:55 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jul 08, 2013 8:43 pm
Posts: 257
win10 x64 home premiun + PB 5.60 beta3 work fine!
Five windows with diferent transparency, or may be my glass.. tired eyes?.. :mrgreen: :mrgreen:

_________________
If translation=Error: reply="Sorry, Im Spanish": Endif


Top
 Profile  
Reply with quote  
 Post subject: Re: [win] Borderless Window : Drop shadow / Transparency
PostPosted: Tue Feb 14, 2017 8:48 pm 
Offline
Addict
Addict
User avatar

Joined: Mon May 26, 2003 3:07 pm
Posts: 1477
Location: Nantes
gurj wrote:
winxp:
setwindowshadow() is spare
win7:
unknown

- windows XP does not support AERO effect.
- On windows vista/7/8/10, shadows are not visible if you disabled the following option in your windows preferences:
Image

_________________
Imagewin8.1 x64 5.31 | IDE | PB plugin | Tools | Sprite | JSON | visual tool


Top
 Profile  
Reply with quote  
 Post subject: Re: [win] Borderless Window : Drop shadow / Transparency
PostPosted: Wed Feb 15, 2017 12:09 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4841
Location: Lyon - France
Cool windows
Thanks for sharing 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: [win] Borderless Window : Drop shadow / Transparency
PostPosted: Mon Sep 28, 2020 7:12 am 
Offline
Addict
Addict
User avatar

Joined: Thu Aug 07, 2003 7:01 pm
Posts: 3164
Location: United Kingdom
@Eddy Do you think something like this could be used to make a program used Windows Dark mode?

Here is what Microsoft added to Terminal for Dark mode:
https://github.com/mintty/wsltty/issues/157

_________________
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 27 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye