StPendl StPendl Dec 7, 2008 - "Corrected link for EX styles to point to Win32 instead of MFC, since LB does not use MFC"

==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([[http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx|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 &H80 Print HexDec(valueHex$) ' Prints 128 [[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 other coding situations. One example is passing parameters to a CallDLL #gdi32. Windows constants for opaque and transparent background colors are [[http://www.jniwrapper.com/jniwrapper_downloads/javadoc/winpack/constant-values.html|BKMODE_OPAQUE]] and [[http://www.jniwrapper.com/jniwrapper_downloads/javadoc/winpack/constant-values.html|BKMODE_TRANSPARENT]] respectively. Since neither of these constants is recognized by [[http://www.libertybasic.com|Liberty BASIC]], then the value of [[http://www.jniwrapper.com/jniwrapper_downloads/javadoc/winpack/constant-values.html|1]] or [[http://www.jniwrapper.com/jniwrapper_downloads/javadoc/winpack/constant-values.html|2]] must be passed into any CallDLL #gdi32 as either a literal or a variable. [[http://www.libertybasic.com|Liberty BASIC]] sees Windows constants as //**Global variables**//. It may be beneficial use the //**Global**// command when specifying any user defined variable such as {{BKMODE.TRANSPARENT}}. The information here can be applied to many other circumstances when the Windows constant is unrecognized by [[http://www.libertybasic.com|Liberty BASIC]] and the decimal value is known to the programmer.