How to restore borders on borderless windows?

Just starting out? Need help? Post your questions and find answers here.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

How to restore borders on borderless windows?

Post by davido »

If I choose to open a window with the #PB_Window_BorderLess flag, is there a way to restore the border during execution of the program at some point?
Preferably cross-platform, please.
DE AA EB
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4991
Joined: Sun Apr 12, 2009 6:27 am

Re: How to restore borders on borderless windows?

Post by RASHAD »

Hi davido
I did the next snippet long time back
I hope it will be as you wished

F12 for toggle bet Border and No Border

Code: Select all

OpenWindow(0,0,0,400,300,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered|#PB_Window_MaximizeGadget)
SetWindowLongPtr_(WindowID(0), #GWL_STYLE,GetWindowLongPtr_(WindowID(0), #GWL_STYLE) &~ #WS_DLGFRAME)
SetWindowColor(0,#Gray)

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
       
      
      Case #PB_Event_Gadget
            Select EventGadget()
             Case 1            
            EndSelect
             
      Case #WM_KEYDOWN
            Run ! 1
            If Run = 0 And EventwParam() = #PB_Shortcut_F12   ;F12 key
               SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) &~ #WS_DLGFRAME)
               SetWindowPos_(WindowID(0), 0, 0, 0, 0, 0, #SWP_FRAMECHANGED| #SWP_DRAWFRAME| #SWP_NOMOVE| #SWP_NOSIZE| #SWP_NOZORDER)
            ElseIf Run = 1 And EventwParam() = #PB_Shortcut_F12
               SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) | #WS_DLGFRAME)
               SetWindowPos_(WindowID(0), 0, 0, 0, 0, 0, #SWP_FRAMECHANGED| #SWP_DRAWFRAME| #SWP_NOMOVE| #SWP_NOSIZE| #SWP_NOZORDER)
            EndIf
            
      Case #WM_LBUTTONDOWN
            If Run = 0
               SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
            EndIf
             
  EndSelect 

Until Quit = 1
End
# 2:
To avoid using EventwParam()

Code: Select all

OpenWindow(0,0,0,400,300,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered|#PB_Window_MaximizeGadget)
SetWindowLongPtr_(WindowID(0), #GWL_STYLE,GetWindowLongPtr_(WindowID(0), #GWL_STYLE) &~ #WS_DLGFRAME)
SetWindowColor(0,#Gray)

AddKeyboardShortcut(0, #PB_Shortcut_F12, 10)
Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
       
      
      Case #PB_Event_Gadget
            Select EventGadget()
             Case 1            
            EndSelect
            
      Case #PB_Event_Menu
             Select EventMenu()
                  Case 10
                          Run ! 1
                          If Run = 0
							               SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) &~ #WS_DLGFRAME)
							               SetWindowPos_(WindowID(0), 0, 0, 0, 0, 0, #SWP_FRAMECHANGED| #SWP_DRAWFRAME| #SWP_NOMOVE| #SWP_NOSIZE| #SWP_NOZORDER)
							            Else
							               SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) | #WS_DLGFRAME)
							               SetWindowPos_(WindowID(0), 0, 0, 0, 0, 0, #SWP_FRAMECHANGED| #SWP_DRAWFRAME| #SWP_NOMOVE| #SWP_NOSIZE| #SWP_NOZORDER)
							            EndIf
						EndSelect
            
      Case #WM_LBUTTONDOWN
            If Run = 0
               SendMessage_(WindowID(0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
            EndIf
             
  EndSelect 

Until Quit = 1
End
Egypt my love
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: How to restore borders on borderless windows?

Post by davido »

Hi RASHAD,

Brilliant!
Thank you very much. :D
I've opted for the 2nd example as the manual indicates that EventwParam() is no longer supported.
DE AA EB
Post Reply