==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** ([[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_Extended_Window_Styles.asp|MSDN Defines a Tool Window here)]]is **[[http://www.jniwrapper.com/jniwrapper_downloads/javadoc/winpack/constant-values.html|128]]**.  With the preceding underscore, [[http://www.libertybasic.com|Liberty BASIC]]accurately interprets that {{constant}}.
----------
[[code format="vb"]]
    Print _WS_EX_TOOLWINDOW ' Prints 128
[[code]]
----------
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.
----------
[[code format="vb"]]
    Stylebits 0, 0, _WS_EX_TOOLWINDOW, 0
[[code]]
is the same as
[[code format="vb"]]
    Stylebits 0, 0, 128, 0
[[code]]
is the same as
[[code format="vb"]]
    exStyle = 128
    Stylebits 0, 0, exStyle, 0
[[code]]
----------

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.
[[code format="vb"]]
    valueHex$ = "80" ' Hexademical &80
    Print HexDec(valueHex$) ' Prints 128
[[code]]
----------

//**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
[[code format="vb"]]
    valueHex$ = "80" ' Hexademical &80
    Print HexDec(valueHex$) ' Prints 128

    valueHex$ = "&80" ' Hexademical &80
    Print HexDec(valueHex$) ' Prints 0
[[code]]
----------

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

[[code format="vb"]]
    value = _WS_EX_TOOLWINDOW
    Print "value = ";value ' Prints 128
    valueHex$ = DecHex$(value)
[[code]]
----------
Demo 1: Opening a Tool Window using the Windows Constant in the Stylebits command
[[code format="vb"]]
' 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
[[code]]
----------
Demo 2: Opening a Tool Window using the literal decimal value in the Stylebits command
[[code format="vb"]]
' 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
[[code]]
----------
Demo 3: Opening a Tool Window using a variable in the Stylebits command
[[code format="vb"]]
' 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
[[code]]
----------
===//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**, [[http://www.google.com/|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
----------
[[code format="vb"]]
    Stylebits #w, 0, 0, _WS_EX_LAYERED, 0
[[code]]
but will happilly accept either

[[code format="vb"]]
    Stylebits #w, 0, 0, 524288, 0
[[code]]
or
[[code format="vb"]]
    WS.EX.LAYERED = 524288
    Stylebits #w, 0, 0, WS.EX.LAYERED, 0
[[code]]
----------
===//Combining Stylebits//===
[[http://lbpe.wikispaces.com/Stylebits+-+Windows|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
[[code format="vb"]]
    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
[[code]]
Demo2: Removing the Maximize and Minimize Buttons using literals and variables in the Stylebits command
[[code format="vb"]]
    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
[[code]]
----------
===//Beyond Stylebits//===
Windows constants can be applied in many circumstances.  The information here will apply to those circumstances as well.