Code: Select all
ChangeWindowAttributes_(WindowID(), AttributeToSet, AttributeToClear)
runtime. You can combine several constants with the Or operand and set or clear
attributes with one call of this function.
My example code demonstrates how to toggle attributes of a displayed window:
Code: Select all
EnableExplicit
ImportC ""
GetWindowAttributes(WindowRef.L, *WindowAttributes)
EndImport
#kWindowCloseBoxAttribute = 1 << 0
#kWindowHorizontalZoomAttribute = 1 << 1
#kWindowVerticalZoomAttribute = 1 << 2
#kWindowFullZoomAttribute = #kWindowVerticalZoomAttribute | #kWindowHorizontalZoomAttribute
#kWindowCollapseBoxAttribute = 1 << 3
#kWindowResizableAttribute = 1 << 4
#kWindowToolbarButtonAttribute = 1 << 6
#kWindowMetalAttribute = 1 << 8
#kWindowNoShadowAttribute = 1 << 21
Define ButtonID.L
Define ButtonText.S
Define i.I
Define NumButtons.I
Define WindowAttributeName.S
Define WindowAttributes.I
Dim WindowAttributeID.L(0)
Dim WindowAttributeName.S(0)
OpenWindow(0, 100, 100, 300, 260, "Toggle Window attributes", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_Invisible)
; ----- Read the constant descriptions and its values into 2 arrays and create buttons
Repeat
Read.S WindowAttributeName
If WindowAttributeName = ""
NumButtons = i
Break
Else
ReDim WindowAttributeID(i)
ReDim WindowAttributeName(i)
WindowAttributeName(i) = WindowAttributeName
Read.L WindowAttributeID(i)
GetWindowAttributes(WindowID(0), @WindowAttributes)
If WindowAttributes & WindowAttributeID(i)
ButtonText = "Disable "
Else
ButtonText = "Enable "
EndIf
ButtonGadget(i, 10, i * 30 + 10, WindowWidth(0) - 20, 20, ButtonText + WindowAttributeName(i))
i + 1
EndIf
ForEver
; ----- Adapt vertical size of window to display all buttons
ResizeWindow(0, #PB_Ignore, #PB_Ignore, #PB_Ignore, NumButtons * 30 + 10)
HideWindow(0, #False)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #PB_Event_Gadget
ButtonID = EventGadget()
; ----- Read current attributes of window
GetWindowAttributes(WindowID(0), @WindowAttributes)
; ----- Toggle the window attribute connected to the pressed button
; and change the text of the button
If WindowAttributes & WindowAttributeID(ButtonID)
ChangeWindowAttributes_(WindowID(0), 0, WindowAttributeID(ButtonID))
ButtonText = "Enable "
Else
ChangeWindowAttributes_(WindowID(0), WindowAttributeID(ButtonID), 0)
ButtonText = "Disable "
EndIf
SetGadgetText(ButtonID, ButtonText + WindowAttributeName(ButtonID))
EndSelect
ForEver
End
DataSection
Data.S "closing of window"
Data.L #kWindowCloseBoxAttribute
Data.S "minimizing to dock"
Data.L #kWindowCollapseBoxAttribute
Data.S "maximizing"
Data.L #kWindowFullZoomAttribute
Data.S "non-shadow look"
Data.L #kWindowNoShadowAttribute
Data.S "toolbar button"
Data.L #kWindowToolbarButtonAttribute
Data.S "resizing of window"
Data.L #kWindowResizableAttribute
Data.S ""
EndDataSection