Stylebits and Windows Constants

Janet Terra


Recognized Windows Constants


Many of the Windows constants are recognized by Liberty BASIC by preceding that constant with an underscore . As an example, the decimal equivalent of WS_EX_TOOLWINDOW ( MSDN Defines a Tool Window here) is 128 . With the preceding underscore, Liberty BASIC accurately interprets that constant .

 Print _WS_EX_TOOLWINDOW ' Prints 128 

While it is most convenient to use the Windows constant itself, the numerical equivalent (either the literal or a variable) can be used just as easily in the Stylebits command.

 Stylebits 0, 0, _WS_EX_TOOLWINDOW, 0 
is the same as
 Stylebits 0, 0, 128, 0 
is the same as
 exStyle = 128 
Stylebits 0, 0, exStyle, 0


This variable must be in decimal (not hexademical) form. If necesssary, use the Liberty BASIC HexDec() function to convert a hexademical value to a decimal value.
 valueHex$ = "80" ' Hexademical &80 
Print HexDec(valueHex$) ' Prints 128


Caution: Although the Help File suggests Hexadecimal strings can be converted to Decimal numbers using the native HexDec() function with or without the preceding & (ampersand), it appears the use of the preceding & (ampersand) yields inconsistent results.


From the Help File
  • HEXDEC( "value" )

  • Description:
  • This function returns a numeric decimal from a hexadecimal number expressed in a string. Hexadecimal values are represented by digits 0 - F. The hexadecimal number can be preceded by the characters "&H". The hexadecimal string must be enclosed in quote marks.

  • Usage:

  • print hexdec( "FF" )

  • or:

  • print hexdec( "&HFF")

However, try this
 valueHex$ = "80" ' Hexademical &80 
Print HexDec(valueHex$) ' Prints 128

valueHex$ = "&80" ' Hexademical &80
Print HexDec(valueHex$) ' Prints 0


For the purposes of this discussion, any preceding & (ampersand) will be omitted from any hexadecimal strings.

 value = _WS_EX_TOOLWINDOW 
Print "value = ";value ' Prints 128
valueHex$ = DecHex$(value)

Demo 1: Opening a Tool Window using the Windows Constant in the Stylebits command
 ' Open a Tool Window 

Nomainwin
Stylebits #w, 0, 0, _WS_EX_TOOLWINDOW, 0
Open "Tool Window" for Window as #w
#w, "Trapclose QuitDemo"

Wait

Sub QuitDemo handle$
Close #handle$
End Sub

Demo 2: Opening a Tool Window using the literal decimal value in the Stylebits command
 ' Open a Tool Window 

Nomainwin
Stylebits #w, 0, 0, 128, 0
Open "Tool Window" for Window as #w
#w, "Trapclose QuitDemo"

Wait

Sub QuitDemo handle$
Close #handle$
End Sub

Demo 3: Opening a Tool Window using a variable in the Stylebits command
 ' Open a Tool Window 

Nomainwin
exStyle = 128
Stylebits #w, 0, 0, exStyle, 0
Open "Tool Window" for Window as #w
#w, "Trapclose QuitDemo"

Wait

Sub QuitDemo handle$
Close #handle$
End Sub

Unrecognized Windows Constants


There are well over 55,000 Windows Constants in use. Many, but not all, Windows constants are recognized by Liberty BASIC. WS_EX_LAYERED is one of the unrecognized constants. Due to the very number of entries alone, a comprehensive list of such constants would be near impossible to find. In the case of the unrecognized WS_EX_LAYERED , Google that constant to find the decimal or hexadecimal equivalent. Remember, if the constant value is given as a hexadecimal string , you must convert that hexadecimal string to the equivalent decimal number . The decimal equivalent of WS_EX_LAYERED is 524288 .

It is best to choose a meaningful variable name. In this case, we'll name the variable WS.EX.LAYERED . Liberty BASIC will halt with an error when trying to use an unrecognized Windows constant

 Stylebits #w, 0, 0, _WS_EX_LAYERED, 0 
but will happilly accept either

 Stylebits #w, 0, 0, 524288, 0 
or
 WS.EX.LAYERED = 524288 
Stylebits #w, 0, 0, WS.EX.LAYERED, 0

Combining Stylebits


Stylebits - Windows shows how to combine two or more Windows constants within the same addbits, removebits, addextendedbits or removeextendedbits of the Stylebits command. Decimal numbers and variables work just as well in combination.

Demo1: Removing the Maximize and Minimize Buttons using Windows Constants in the Stylebits command
 Stylebits #w, 0, _WS_MAXIMIZEBOX or _WS_MINIMIZEBOX, 0, 0 
Open "No Max/Min Boxes" for Window as #w
#w, "Trapclose QuitDemo"
Wait

Sub QuitDemo handle$
Close #handle$
End
End Sub
Demo2: Removing the Maximize and Minimize Buttons using literals and variables in the Stylebits command
 WS.MAXIMIZEBOX = 65536 
Stylebits #w, 0, 131072 or WS.MAXIMIZEBOX, 0, 0
Open "No Max/Min Boxes" for Window as #w
#w, "Trapclose QuitDemo"
Wait

Sub QuitDemo handle$
Close #handle$
End
End Sub

Beyond Stylebits


Windows constants can be applied in many circumstances. other coding situations. One example is passing parameters to a CallDLL #gdi32. Windows constants for opaque and transparent background colors are BKMODE_OPAQUE and BKMODE_TRANSPARENT respectively. Since neither of these constants are recognized by Liberty BASIC , then the value of 1 or 2 must be passed into any CallDLL #gdi32 as either a literal or a variable. The information here will apply to those circumstances as well. can be applied to many other circumstances.