StPendl
Aug 16, 2013
- "changed syntax highlighting to LB"
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 a Default Button
A default button is the button that will be triggered with the Enter key, as long as the dialog window has focus. Without stylebits, a default button is only possible in a Dialog Window and then only if the button has the extension default. Brent Thorn posted code using Stylebits _BS_DEFPUSHBUTTON to assign a default button in a regular window with any extension. Thanks, Brent! Be sure to give focus to the dialog window by setting focus to one of the (non-button) controls prior to the activation of the default button. A simple Setfocus to a textbox (any textbox) will accomplish that. Here is a modification of Brent's code.
'Using a Default Button in a Regular Window'Thanks to Brent Thorn' http://libertybasic.conforums.com/index.cgi?board=novice&action=display&num=1134254812'Modifications by Janet = Menu and Setfocus to #main.tbx1WindowWidth=300WindowHeight=350UpperLeftX=Int((DisplayWidth-WindowWidth)/2)UpperLeftY=Int((DisplayHeight-WindowHeight)/2)Menu#main,"&Options","E&xit", EndDemoMenu
Textbox#main.tbx1,150,50,120,30Textbox#main.tbx2,150,100,120,30Textbox#main.tbx3,150,150,120,30Textbox#main.tbx4,150,200,120,30Stylebits#main.default, _BS_DEFPUSHBUTTON,0,0,0Button#main.default,"", DefaultButton, UL,-100,-100Open"Default Button in a Regular Window"forWindowas#main
#main "Trapclose EndDemo"#main.textbox"!Setfocus"WaitSub DefaultButton handle$
#main.tbx1 "!Contents? text1$"#main.tbx2 "!Contents? text2$"#main.tbx3 "!Contents? text3$"#main.tbx4 "!Contents? text4$"Notice"The textboxes read";Chr$(13);Chr$(13)+ _
text1$;Chr$(13);text2$;Chr$(13);text3$;Chr$(13);text4$
EndSubSub EndDemoMenu
Call EndDemo "#main"EndSubSub EndDemo handle$
Close#main
EndEndSub
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,00,0, _WS_EX_CLIENTEDGE or _WS_EX_DLGMODALFRAME,0
This demo shows some of the border effects that can be achieved with stylebits
WindowWidth=600WindowHeight=560UpperLeftX=Int((DisplayWidth-WindowWidth)/2)UpperLeftY=Int((DisplayHeight-WindowHeight)/3)NomainwinButton#demo.bttn1,"One", Click, UL,20,60,80,40
bttnText1$ ="0, 0, 0, 0 'No Stylebits"Statictext#demo, bttnText1$,180,70,400,30Button#demo.bttn2,"Two", Click, UL,20,120,80,40
bttnText2$ ="_WS_BORDER, 0, 0, 0"Stylebits#demo.bttn2, _WS_BORDER,0,0,0Statictext#demo, bttnText2$,180,130,400,30Button#demo.bttn3,"Three", Click, UL,20,180,80,40
bttnText3$ ="_WS_DLGFRAME, 0, 0, 0"Stylebits#demo.bttn3, _WS_DLGFRAME,0,0,0Statictext#demo, bttnText3$,180,190,400,30Button#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,0Statictext#demo, bttnText4$,180,250,400,90Button#demo.bttn5,"Five", Click, UL,20,360,80,40
bttnText5$ ="0, 0, _WS_EX_CLIENTEDGE, 0"Stylebits#demo.bttn5,0,0, _WS_EX_CLIENTEDGE,0Statictext#demo, bttnText5$,180,370,400,30Button#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,0Statictext#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,60Open"Button Effects with Stylebits"forWindowas#demo
#demo "Trapclose EndDemo"#demo "Font Times_New_Roman 14 Bold"WaitSub EndDemo handle$
Close#demo
EndEndSubSub Click handle$
nButton$ =Right$(handle$,1)Notice"Button #";nButton$;" Clicked"EndSub
Stylebits 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=600WindowHeight=560UpperLeftX=Int((DisplayWidth-WindowWidth)/2)UpperLeftY=Int((DisplayHeight-WindowHeight)/3)NomainwinButton#demo.bttn1,"Button 1", Click, UL,100,100,120,40Stylebits#demo.bttn1,0,0,0,0Button#demo.bttn2,"Button 2", Click, UL,100,200,120,40Stylebits#demo.bttn2,0,0,0,0Button#demo.bttn3,"Button 3", Click, UL,320,100,120,40Stylebits#demo.bttn3,0,0,0,0Button#demo.bttn4,"Button 4", Click, UL,320,200,120,40Stylebits#demo.bttn4,0,0,0,0Button#demo.bttn5,"Exit", endDemo, UL,100,300,120,40Statictext#demo,"0, _WS_TABSTOP, 0, 0",40,350,200,30Stylebits#demo.bttn5,0, _WS_TABSTOP,0,0Textbox#demo.txtbx,320,300,120,40Stylebits#demo.txtbx,0, _WS_TABSTOP,0,0Statictext#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,120Open"Button Effects with Stylebits"forWindowas#demo
#demo "Trapclose EndDemo"#demo "Font Times_New_Roman 14 Bold"#demo.bttn4 "!Setfocus"WaitSub 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=600WindowHeight=560UpperLeftX=Int((DisplayWidth-WindowWidth)/2)UpperLeftY=Int((DisplayHeight-WindowHeight)/3)NomainwinButton#demo.bttn1,"Default", Click, UL,20,80,120,80Statictext#demo,"0, 0, 0, 0",44,165,260,60Button#demo.bttn2,"Multiline Text on a Button", Click, UL,20,230,120,80Stylebits#demo.bttn2, _BS_MULTILINE,0,0,0Statictext#demo,"_BS_MULTILINE, 0, 0, 0",20,315,260,60Button#demo.bttn3,"Text@Bottom", Click, UL,300,80,120,80Stylebits#demo.bttn3, _BS_BOTTOM,0,0,0Statictext#demo,"_BS_BOTTOM, 0, 0, 0",300,165,260,260Button#demo.bttn4,"Text@Top", Click, UL,300,230,120,80Stylebits#demo.bttn4, _BS_TOP,0,0,0Statictext#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,120Open"Button Formatting with Stylebits"forWindowas#demo
#demo "Trapclose EndDemo"#demo "Font Times_New_Roman 14 Bold"#demo.bttn4 "!Setfocus"WaitSub 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 a Default Button
A default button is the button that will be triggered with the Enter key, as long as the dialog window has focus. Without stylebits, a default button is only possible in a Dialog Window and then only if the button has the extension default. Brent Thorn posted code using Stylebits _BS_DEFPUSHBUTTON to assign a default button in a regular window with any extension. Thanks, Brent! Be sure to give focus to the dialog window by setting focus to one of the (non-button) controls prior to the activation of the default button. A simple Setfocus to a textbox (any textbox) will accomplish that. Here is a modification of Brent's code.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.
This demo shows some of the border effects that can be achieved with stylebits
Stylebits 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.
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_MULTLINEThis third demo demonstrates button text formatting with stylebitsStylebits 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 - Button Styles.