[Solved] shadow window

Windows specific forum
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

[Solved] shadow window

Post by mestnyi »

borderless windows how to make shadow?
This is what I got

Code: Select all

OpenWindow(0, 550, 350, 0, 0, "", #PB_Window_BorderLess)
ButtonGadget(2,0,0,320,200,"button")

;\\
 SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) | #WS_SIZEBOX );
  
;\\
ResizeWindow(0,#PB_Ignore,#PB_Ignore,320,200)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
and here's another option

Code: Select all

Global oldProc, DWMEnabled

Procedure WndCallback(hWnd, Msg, wParam, lParam)
  Select Msg
      
    Case #WM_NCCALCSIZE
      If wParam
        ProcedureReturn 1
      EndIf
      
  EndSelect
  ProcedureReturn #PB_ProcessPureBasicEvents ;CallWindowProc_(oldProc, hWnd, Msg, wParam, lParam)
EndProcedure

OpenWindow(0, 550, 350, 0, 0, "", #PB_Window_BorderLess)
ButtonGadget(2,0,0,320,200,"button")

SetWindowCallback(@WndCallback(), 0)
SetRect_(@Margin.RECT, 1, 0, 1, 0)
If OpenLibrary(0, "dwmapi.dll")
  CallFunction(0, "DwmExtendFrameIntoClientArea", WindowID(0), @Margin)
  CallFunction(0, "DwmIsCompositionEnabled", @DWMEnabled)
  If DWMEnabled=0
    MessageRequester("Info", "Desktop composition is disabled! Sorry, no shadow...")
    SetWindowTheme_(WindowID(0), "", "")
  EndIf
  CloseLibrary(0)
EndIf

SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) | #WS_SIZEBOX );
SetWindowPos_(WindowID(0), 0, 0, 0, 0, 0, #SWP_NOSIZE|#SWP_NOMOVE|#SWP_FRAMECHANGED|#SWP_SHOWWINDOW)

;\\
ResizeWindow(0,#PB_Ignore,#PB_Ignore,320,200)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
Last edited by mestnyi on Sat Oct 21, 2023 10:00 pm, edited 1 time in total.
User avatar
Bisonte
Addict
Addict
Posts: 1313
Joined: Tue Oct 09, 2007 2:15 am

Re: has shadow window

Post by Bisonte »

Code: Select all

OpenWindow(0, 0, 0, 640, 480, "Test", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
SetClassLongPtr_(WindowID(0), #GCL_STYLE, #CS_DROPSHADOW)
HideWindow(0, #False)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
Important is #PB_Window_Invisible and HideWindow().... Without them, there is no shadow....
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: has shadow window

Post by mestnyi »

thank you
only that's how I need it, it doesn't work.

Code: Select all

OpenWindow(0, 0, 0, 0, 0, "Test", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
ButtonGadget(2,0,0,320,200,"button")
SetClassLongPtr_(WindowID(0), #GCL_STYLE, GetClassLongPtr_(WindowID(0), #GCL_STYLE) | #CS_DROPSHADOW)
HideWindow(0, #False, #PB_Window_NoActivate)

;\\
ResizeWindow(0,#PB_Ignore,#PB_Ignore,320,200)

While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: has shadow window

Post by RASHAD »

#1 :

Code: Select all

OpenWindow(0, 0, 0, 640,400, "Test", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
SetClassLongPtr_(WindowID(0), #GCL_STYLE, GetWindowLongPtr_(WindowID(0),#GCL_STYLE)|#CS_DROPSHADOW)
ButtonGadget(2,0,0,320,200,"button")
HideWindow(0, #False)
ResizeWindow(0,#PB_Ignore,#PB_Ignore,320,200)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
#2 :

Code: Select all

Procedure winCB(hwnd, uMsg, wParam, lParam)
  result = #PB_ProcessPureBasicEvents 
  Select uMsg      
    Case #WM_NCCALCSIZE
        *rc.RECT = lParam
        *rc\top - 6
  EndSelect     
 
  ProcedureReturn result 
EndProcedure

OpenWindow(0, 0,0,320,200, "", #PB_Window_BorderLess|#WS_SIZEBOX |#PB_Window_ScreenCentered)
ButtonGadget(2,0,0,320,206,"button")
WindowBounds(0,320,200,320,200)
SetWindowCallback(@winCB())
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
Egypt my love
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: has shadow window

Post by mestnyi »

RASHAD wrote: Sat Oct 21, 2023 3:12 pm OpenWindow(0, 0, 0, 640,400, "Test", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)

Code: Select all

OpenWindow(0, 0, 0, 1, 1, "Test", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
yes that's how it works :D
but the shadow is different from the system one.
I also made this option, I don’t know how it will show itself in practice :)

Code: Select all

Global shadow
Procedure Resize_PopupWindowEvents( )
   Protected win = EventWindow( )
   Protected x = WindowX(win, #PB_Window_FrameCoordinate)
   Protected y = WindowY(win, #PB_Window_FrameCoordinate)
   Protected width = WindowWidth(win, #PB_Window_InnerCoordinate)
   Protected height = WindowHeight(win, #PB_Window_InnerCoordinate)
   Protected bx = WindowWidth(shadow, #PB_Window_FrameCoordinate)-WindowWidth(shadow, #PB_Window_InnerCoordinate)
   Protected by = WindowHeight(shadow, #PB_Window_FrameCoordinate)-WindowHeight(shadow, #PB_Window_InnerCoordinate)
   
   ResizeWindow(shadow, x, y, width-bx, height-by)
EndProcedure

Procedure Create_PopupWindow( window, parentID=0 )
   shadow = OpenWindow(#PB_Any, 0,0,0,0, "Test", #PB_Window_TitleBar|#PB_Window_Invisible, parentID)
   OpenWindow(window, 0,0,0,0, "Test", #PB_Window_BorderLess, WindowID(shadow))
   HideWindow(shadow,0, #PB_Window_NoActivate)
   BindEvent(#PB_Event_MoveWindow, @Resize_PopupWindowEvents(), 0)
   BindEvent(#PB_Event_SizeWindow, @Resize_PopupWindowEvents(), 0)
EndProcedure

Create_PopupWindow( 0 )
ListViewGadget(2,0,0,320,200)
For i=0 To 20
   AddGadgetItem(2,-1,"item_"+Str(i))
Next

;\\
ResizeWindow(0,550,350,320,200)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: [Solved] shadow window

Post by mestnyi »

Bisonte wrote: Sat Oct 21, 2023 6:32 am

Code: Select all

OpenWindow(0, 0, 0, 640, 480, "Test", #PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Invisible)
SetClassLongPtr_(WindowID(0), #GCL_STYLE, #CS_DROPSHADOW)
HideWindow(0, #False)
While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
Important is #PB_Window_Invisible and HideWindow().... Without them, there is no shadow....
I settled on this, it works the same on both XP and Windows 10.
thanks to everyone who was not indifferent.
Post Reply