Change FrameGadget style with recreating it?
Change FrameGadget style with recreating it?
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?
Re: Change FrameGadget style with recreating it?
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
Re: Change FrameGadget style with recreating it?
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
Re: Change FrameGadget style with recreating it?
You have to remove the previously set flags...
It is much easier if you use something like WinSpy++ (or WinDetective, WinSpector, ...) to investigate the style/exstyle
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
Et cetera is my worst enemy
Re: Change FrameGadget style with recreating it?
Ah, thanks!