Change FrameGadget style with recreating it?

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Change FrameGadget style with recreating it?

Post by BarryG »

The FrameGadget has these style flags: #PB_Frame_Single, #PB_Frame_Double, and #PB_Frame_Flat. Can these be changed at runtime without recreating the gadget?
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Change FrameGadget style with recreating it?

Post by chi »

If you create the FrameGadget without any flags, PB uses the Button Class to draw the control. With any of the 3 flags specified, you get a Static control. So you can switch between Single/Double/Flat but you can't switch back to the original style because it uses a different class to render.
Et cetera is my worst enemy
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Change FrameGadget style with recreating it?

Post by BarryG »

Okay, so I tried this but it doesn't cycle past the third change for some reason. What am I doing wrong?

Code: Select all

If OpenWindow(0, 400, 400, 320, 150, "FrameGadget", #PB_Window_SystemMenu)
  hWnd=FrameGadget(0, 10, 20, 300, 50, "Frame Border Test", #PB_Frame_Single)
  ButtonGadget(1, 10, 80, 300, 50, "Click to switch styles")
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget And EventGadget()=1
      n+1
      Select n
        Case 1 : SetWindowLongPtr_(hWnd,#GWL_STYLE,GetWindowLongPtr_(hWnd,#GWL_STYLE)|#WS_BORDER)
        Case 2 : SetWindowLongPtr_(hWnd,#GWL_EXSTYLE,GetWindowLongPtr_(hWnd,#GWL_EXSTYLE)|#WS_EX_DLGMODALFRAME)
        Case 3 : SetWindowLongPtr_(hWnd,#GWL_EXSTYLE,GetWindowLongPtr_(hWnd,#GWL_EXSTYLE)|#WS_EX_CLIENTEDGE)
        Default : n=0 : SetWindowLongPtr_(hWnd,#GWL_EXSTYLE,GetWindowLongPtr_(hWnd,#GWL_EXSTYLE)|#WS_EX_STATICEDGE)
      EndSelect
      SetWindowPos_(hWnd,0,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE|#SWP_NOOWNERZORDER|#SWP_DRAWFRAME)
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: Change FrameGadget style with recreating it?

Post by chi »

You have to remove the previously set flags...

Code: Select all

If OpenWindow(0, 400, 400, 320, 150, "FrameGadget", #PB_Window_SystemMenu)
  hWnd=FrameGadget(0, 10, 20, 300, 50, "Frame Border Test", #PB_Frame_Single)
  ButtonGadget(1, 10, 80, 300, 50, "Click to switch styles")
  Repeat
    ev=WaitWindowEvent()
    If ev=#PB_Event_Gadget And EventGadget()=1
      n+1
      Select n
        Case 1
          SetWindowLongPtr_(hWnd,#GWL_STYLE,GetWindowLongPtr_(hWnd,#GWL_STYLE)|#WS_BORDER)
          SetWindowLongPtr_(hWnd,#GWL_EXSTYLE,GetWindowLongPtr_(hWnd,#GWL_EXSTYLE)&~#WS_EX_STATICEDGE)
        Case 2
          SetWindowLongPtr_(hWnd,#GWL_STYLE,GetWindowLongPtr_(hWnd,#GWL_STYLE)&~#WS_BORDER)
          SetWindowLongPtr_(hWnd,#GWL_EXSTYLE,GetWindowLongPtr_(hWnd,#GWL_EXSTYLE)|#WS_EX_DLGMODALFRAME)
        Case 3
          SetWindowLongPtr_(hWnd,#GWL_EXSTYLE,GetWindowLongPtr_(hWnd,#GWL_EXSTYLE)&~#WS_EX_WINDOWEDGE&~#WS_EX_DLGMODALFRAME|#WS_EX_CLIENTEDGE)
        Default
          SetWindowLongPtr_(hWnd,#GWL_EXSTYLE,GetWindowLongPtr_(hWnd,#GWL_EXSTYLE)&~#WS_EX_CLIENTEDGE|#WS_EX_STATICEDGE)
          n=0
      EndSelect
      SetWindowPos_(hWnd,0,0,0,0,0,#SWP_NOMOVE|#SWP_NOSIZE|#SWP_NOZORDER|#SWP_NOACTIVATE|#SWP_DRAWFRAME)
    EndIf
  Until ev=#PB_Event_CloseWindow
EndIf
It is much easier if you use something like WinSpy++ (or WinDetective, WinSpector, ...) to investigate the style/exstyle ;)
Et cetera is my worst enemy
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Change FrameGadget style with recreating it?

Post by BarryG »

Ah, thanks!
Post Reply