JanetTerra
Oct 29, 2007
- "Edited to pass handles as uLong"
Reviewing the Stylebits Parameters
The four parameters of stylebits are AddBit, RemoveBit, AddExtendedBit, RemoveExtendedBit. For a review of these four parameters, and an introduction to Stylebits in general, please view Stylebits - Windows.
Stylebits and Button Labels
Many of the stylebits statictext border effects can be obtained with buttons as well. Use the same windows style _WS_ prefixes seen in changing window and other control edges. You can even add a titlebar to a button. These stylebits give a bit of variety to the button appearance and may enhance the overall 3D effect.
Pressing the TAB key can cycle focus from one control to the next. The cycling order is the same order as that which the controls are created. Sometimes it may be desirable to not include a control in the tabbed cycle. The programmer may not want the QUIT button to be included in the TAB Cycle so that the user doesn't inadvertently exit a program prematurely. Assigning the stylebit _WS_TABSTOP to the RemoveBit (second) stylebits parameter will keep that button from gaining focus in the TAB sequence. The button does remain active and will receive focus when mouseclicked.
WindowWidth = 600
WindowHeight = 560
UpperLeftX = Int((DisplayWidth-WindowWidth)/2)
UpperLeftY = Int((DisplayHeight-WindowHeight)/3)
Nomainwin
Button #demo.bttn1, "Button 1", Click, UL, 100, 100, 120, 40
Stylebits #demo.bttn1, 0, 0, 0, 0
Button #demo.bttn2, "Button 2", Click, UL, 100, 200, 120, 40
Stylebits #demo.bttn2, 0, 0, 0, 0
Button #demo.bttn3, "Button 3", Click, UL, 320, 100, 120, 40
Stylebits #demo.bttn3, 0, 0, 0, 0
Button #demo.bttn4, "Button 4", Click, UL, 320, 200, 120, 40
Stylebits #demo.bttn4, 0, 0, 0, 0
Button #demo.bttn5, "Exit", endDemo, UL, 100, 300, 120, 40
Statictext #demo, "0, _WS_TABSTOP, 0, 0", 40, 350, 200, 30
Stylebits #demo.bttn5, 0, _WS_TABSTOP, 0, 0
Textbox #demo.txtbx, 320, 300, 120, 40
Stylebits #demo.txtbx, 0, _WS_TABSTOP, 0, 0
Statictext #demo, "0, _WS_TABSTOP, 0, 0", 320, 350, 200, 30
msg$ = "Use the TAB key to maneuver from one button to the next. " + _
"The button with focus has a darkened outline. The removal of " + _
"_WS_TABSTOP stylebits prevents the EXIT button and the textbox " + _
"from being part of the tabbed cycle. Note that one button must " + _
"receive focus before the TAB key can be recognized."
StaticText #demo.txt5, msg$, 20, 390, 560, 120
Open"Button Effects with Stylebits"for Window as #demo
#demo, "Trapclose EndDemo"
#demo, "Font Times_New_Roman 14 Bold"
#demo.bttn4, "!Setfocus"
Wait
Sub EndDemo handle$
Close #demo
EndEndSubSub Click handle$
nButton$ = Right$(handle$, 1)
Notice "Button #";nButton$;" Clicked"EndSub
Stylebits and Formatted Text Labels
The stylebits commands to format button text labels are similar to those _ES_ textbox and statictext formatting commands. Button formatting style commands begin with _BS_. The default style is text that remains on one line centered both vertically and horizontally. With stylebits, you can left justify, right justify, center, place text at the top of the button and place text at the bottom of the button. The most useful of these stylebits is the _BS_MULTILINE which allows word wrapping and multiline button labels.
_BS_LEFT
_BS_CENTER 'The Default
_BS_RIGHT
_BS_TOP
_BS_BOTTOM
_BS_MULTLINE
This third demo demonstrates button text formatting with stylebits
WindowWidth = 600
WindowHeight = 560
UpperLeftX = Int((DisplayWidth-WindowWidth)/2)
UpperLeftY = Int((DisplayHeight-WindowHeight)/3)
Nomainwin
Button #demo.bttn1, "Default", Click, UL, 20, 80, 120, 80
Statictext #demo, "0, 0, 0, 0", 44, 165, 260, 60
Button #demo.bttn2, "Multiline Text on a Button", Click, UL, 20, 230, 120, 80
Stylebits #demo.bttn2, _BS_MULTILINE, 0, 0, 0
Statictext #demo, "_BS_MULTILINE, 0, 0, 0", 20, 315, 260, 60
Button #demo.bttn3, "Text@Bottom", Click, UL, 300, 80, 120, 80
Stylebits #demo.bttn3, _BS_BOTTOM, 0, 0, 0
Statictext #demo, "_BS_BOTTOM, 0, 0, 0", 300, 165, 260, 260
Button #demo.bttn4, "Text@Top", Click, UL, 300, 230, 120, 80
Stylebits #demo.bttn4, _BS_TOP, 0, 0, 0
Statictext #demo, "_BS_TOP, 0, 0, 0", 300, 315, 260, 60
msg$ = "See API Corner - Easy BMPButtons by Alyce Watson " + _
"in the Liberty BASIC Newsletter Issue #123 to learn how the " + _
"Stylebit _BS_BITMAP is used to create a more Windows " + _
"conforming look to your buttons. "
StaticText #demo.txt5, msg$, 20, 370, 560, 120
Open"Button Formatting with Stylebits"for Window as #demo
#demo, "Trapclose EndDemo"
#demo, "Font Times_New_Roman 14 Bold"
#demo.bttn4, "!Setfocus"
Wait
Sub EndDemo handle$
Close #demo
EndEndSubSub Click handle$
nButton$ = Right$(handle$, 1)
Notice "Button #";nButton$;" Clicked"EndSub
Stylebits and API Calls
Stylebits allow buttons to display images, but only when accompanied by an API call to user32.dll (SendMessageA). For an indepth explanation of placing images on button controls, see API Corner - Easy BmpButtons (Liberty BASIC Newsletter, May, 2004) by Alyce Watson. In this referenced article, Alyce also explains how using Stylebits with BmpButtons preserves the intended recessed look of the button when clicked, rather than the inverse color effect on the non-Stylebits native Liberty Basic BmpButton. If you use the _BS_BITMAP stylebit, be sure to include the height and width of the bitmap as the height and width of the button. Otherwise, the button size defaults to that of the null character of the chosen font. As with statictext, you can combine _BS_BITMAP with border styles to achieve interesting effects. Try making colorful buttons in your program without having to preload bitmap images.
Reviewing the Stylebits Parameters
The four parameters of stylebits are AddBit, RemoveBit, AddExtendedBit, RemoveExtendedBit. For a review of these four parameters, and an introduction to Stylebits in general, please view Stylebits - Windows.
Stylebits and Button Labels
Many of the stylebits statictext border effects can be obtained with buttons as well. Use the same windows style _WS_ prefixes seen in changing window and other control edges. You can even add a titlebar to a button. These stylebits give a bit of variety to the button appearance and may enhance the overall 3D effect.
_WS_BORDER, 0, 0, 0 _WS_DLGFRAME _WS_CAPTION, _WS_MAXIMIZEBOX 0, 0, _WS_EX_CLIENTEDGE, 0 0, 0, _WS_EX_CLIENTEDGE or _WS_EX_DLGMODALFRAME, 0This demo shows some of the border effects that can be achieved with stylebitsWindowWidth = 600 WindowHeight = 560 UpperLeftX = Int((DisplayWidth-WindowWidth)/2) UpperLeftY = Int((DisplayHeight-WindowHeight)/3) Nomainwin Button #demo.bttn1, "One", Click, UL, 20, 60, 80, 40 bttnText1$ = "0, 0, 0, 0 'No Stylebits" Statictext #demo, bttnText1$, 180, 70, 400, 30 Button #demo.bttn2, "Two", Click, UL, 20, 120, 80, 40 bttnText2$ = "_WS_BORDER, 0, 0, 0" Stylebits #demo.bttn2, _WS_BORDER, 0, 0, 0 Statictext #demo, bttnText2$, 180, 130, 400, 30 Button #demo.bttn3, "Three", Click, UL, 20, 180, 80, 40 bttnText3$ = "_WS_DLGFRAME, 0, 0, 0" Stylebits #demo.bttn3, _WS_DLGFRAME, 0, 0, 0 Statictext #demo, bttnText3$, 180, 190, 400, 30 Button #demo.bttn4, "Four", Click, UL, 20, 240, 80, 100 bttnText4$ = "_WS_CAPTION, _WS_MAXIMIZEBOX, 0, 0";Chr$(13) + _ "Remove maximize ability or double clicking caption will cause " + _ "button to expand to size of window." Stylebits #demo.bttn4, _WS_CAPTION, _WS_MAXIMIZEBOX, 0, 0 Statictext #demo, bttnText4$, 180, 250, 400, 90 Button #demo.bttn5, "Five", Click, UL, 20, 360, 80, 40 bttnText5$ = "0, 0, _WS_EX_CLIENTEDGE, 0" Stylebits #demo.bttn5, 0, 0, _WS_EX_CLIENTEDGE, 0 Statictext #demo, bttnText5$, 180, 370, 400, 30 Button #demo.bttn6, "Six", Click, UL, 20, 420, 80, 40 bttnText6$ = "0, 0, _WS_EX_CLIENTEDGE or _WS_EX_DLGMODALFRAME, 0" Stylebits #demo.bttn6, 0, 0, _WS_EX_CLIENTEDGE or _WS_EX_DLGMODALFRAME, 0 Statictext #demo, bttnText6$, 180, 420, 400, 60 msg$ = "These are only a few examples of button borders available with " + _ "stylebits. Experiment to find others." Statictext #demo, msg$, 20, 480, 560, 60 Open "Button Effects with Stylebits" for Window as #demo #demo, "Trapclose EndDemo" #demo, "Font Times_New_Roman 14 Bold" Wait Sub EndDemo handle$ Close #demo End End Sub Sub Click handle$ nButton$ = Right$(handle$, 1) Notice "Button #";nButton$;" Clicked" End SubStylebits and Tabbing
Pressing the TAB key can cycle focus from one control to the next. The cycling order is the same order as that which the controls are created. Sometimes it may be desirable to not include a control in the tabbed cycle. The programmer may not want the QUIT button to be included in the TAB Cycle so that the user doesn't inadvertently exit a program prematurely. Assigning the stylebit _WS_TABSTOP to the RemoveBit (second) stylebits parameter will keep that button from gaining focus in the TAB sequence. The button does remain active and will receive focus when mouseclicked.
WindowWidth = 600 WindowHeight = 560 UpperLeftX = Int((DisplayWidth-WindowWidth)/2) UpperLeftY = Int((DisplayHeight-WindowHeight)/3) Nomainwin Button #demo.bttn1, "Button 1", Click, UL, 100, 100, 120, 40 Stylebits #demo.bttn1, 0, 0, 0, 0 Button #demo.bttn2, "Button 2", Click, UL, 100, 200, 120, 40 Stylebits #demo.bttn2, 0, 0, 0, 0 Button #demo.bttn3, "Button 3", Click, UL, 320, 100, 120, 40 Stylebits #demo.bttn3, 0, 0, 0, 0 Button #demo.bttn4, "Button 4", Click, UL, 320, 200, 120, 40 Stylebits #demo.bttn4, 0, 0, 0, 0 Button #demo.bttn5, "Exit", endDemo, UL, 100, 300, 120, 40 Statictext #demo, "0, _WS_TABSTOP, 0, 0", 40, 350, 200, 30 Stylebits #demo.bttn5, 0, _WS_TABSTOP, 0, 0 Textbox #demo.txtbx, 320, 300, 120, 40 Stylebits #demo.txtbx, 0, _WS_TABSTOP, 0, 0 Statictext #demo, "0, _WS_TABSTOP, 0, 0", 320, 350, 200, 30 msg$ = "Use the TAB key to maneuver from one button to the next. " + _ "The button with focus has a darkened outline. The removal of " + _ "_WS_TABSTOP stylebits prevents the EXIT button and the textbox " + _ "from being part of the tabbed cycle. Note that one button must " + _ "receive focus before the TAB key can be recognized." StaticText #demo.txt5, msg$, 20, 390, 560, 120 Open "Button Effects with Stylebits" for Window as #demo #demo, "Trapclose EndDemo" #demo, "Font Times_New_Roman 14 Bold" #demo.bttn4, "!Setfocus" Wait Sub EndDemo handle$ Close #demo End End Sub Sub Click handle$ nButton$ = Right$(handle$, 1) Notice "Button #";nButton$;" Clicked" End SubStylebits and Formatted Text Labels
The stylebits commands to format button text labels are similar to those _ES_ textbox and statictext formatting commands. Button formatting style commands begin with _BS_. The default style is text that remains on one line centered both vertically and horizontally. With stylebits, you can left justify, right justify, center, place text at the top of the button and place text at the bottom of the button. The most useful of these stylebits is the _BS_MULTILINE which allows word wrapping and multiline button labels.
_BS_LEFT _BS_CENTER 'The Default _BS_RIGHT _BS_TOP _BS_BOTTOM _BS_MULTLINEThis third demo demonstrates button text formatting with stylebitsWindowWidth = 600 WindowHeight = 560 UpperLeftX = Int((DisplayWidth-WindowWidth)/2) UpperLeftY = Int((DisplayHeight-WindowHeight)/3) Nomainwin Button #demo.bttn1, "Default", Click, UL, 20, 80, 120, 80 Statictext #demo, "0, 0, 0, 0", 44, 165, 260, 60 Button #demo.bttn2, "Multiline Text on a Button", Click, UL, 20, 230, 120, 80 Stylebits #demo.bttn2, _BS_MULTILINE, 0, 0, 0 Statictext #demo, "_BS_MULTILINE, 0, 0, 0", 20, 315, 260, 60 Button #demo.bttn3, "Text@Bottom", Click, UL, 300, 80, 120, 80 Stylebits #demo.bttn3, _BS_BOTTOM, 0, 0, 0 Statictext #demo, "_BS_BOTTOM, 0, 0, 0", 300, 165, 260, 260 Button #demo.bttn4, "Text@Top", Click, UL, 300, 230, 120, 80 Stylebits #demo.bttn4, _BS_TOP, 0, 0, 0 Statictext #demo, "_BS_TOP, 0, 0, 0", 300, 315, 260, 60 msg$ = "See API Corner - Easy BMPButtons by Alyce Watson " + _ "in the Liberty BASIC Newsletter Issue #123 to learn how the " + _ "Stylebit _BS_BITMAP is used to create a more Windows " + _ "conforming look to your buttons. " StaticText #demo.txt5, msg$, 20, 370, 560, 120 Open "Button Formatting with Stylebits" for Window as #demo #demo, "Trapclose EndDemo" #demo, "Font Times_New_Roman 14 Bold" #demo.bttn4, "!Setfocus" Wait Sub EndDemo handle$ Close #demo End End Sub Sub Click handle$ nButton$ = Right$(handle$, 1) Notice "Button #";nButton$;" Clicked" End SubStylebits and API Calls
Stylebits allow buttons to display images, but only when accompanied by an API call to user32.dll (SendMessageA). For an indepth explanation of placing images on button controls, see API Corner - Easy BmpButtons (Liberty BASIC Newsletter, May, 2004) by Alyce Watson. In this referenced article, Alyce also explains how using Stylebits with BmpButtons preserves the intended recessed look of the button when clicked, rather than the inverse color effect on the non-Stylebits native Liberty Basic BmpButton. If you use the _BS_BITMAP stylebit, be sure to include the height and width of the bitmap as the height and width of the button. Otherwise, the button size defaults to that of the null character of the chosen font. As with statictext, you can combine _BS_BITMAP with border styles to achieve interesting effects. Try making colorful buttons in your program without having to preload bitmap images.
These are just some examples of what you can do with stylebits and buttons. With experimentation, you may find more.
A List of Stylebits
You can get a list of all dwStyles and dwExStyles available with the Stylebits command at the MSDN Library Center.