• No results found

Windows Controls

In document Win32_API_tutorials (Page 107-121)

Step 5: Assignment 2 to see if you can visualized ―a little‖ on what is going on

17. Windows Controls

A control is a child window that an application uses in conjunction with another window to enable user interaction. Controls are most often used within dialog boxes, but they can also be used in other windows. Controls within dialog boxes provide the user with a way to type text, choose options, and initiate actions. Controls in other windows provide a variety of services, such as letting the user choose commands, view status, and view and edit text.

Of course, you are not limited to using only the predefined classes. By calling

RegisterClassEx your program can create its own window classes. However, for most purposes, using one of the predefined classes is best when creating some sort of control, especially if one already exists.

Typically, a program uses these classes to create controls. Each class also has a unique set of window style flags that only apply to it. These unique styles typically control properties specific to that type of control. Below is a list of some of the window classes predefined in the Windows API. Note that this list does not (yet) include all classes defined in the Windows API. Information that applies to all window classes in general appears first in the list.

The common controls overview documentation describes the common controls delivered in Microsoft Windows and the programming elements used to create and manipulate them.

The following table lists the Windows controls.

Control Description

Animation A window that displays an Audio-Video Interleaved (AVI) clip.

Button Notifies the parent window when the user selects the control.

Combo Box A combination of a list box and an edit control, enabling the user to select or add items.

ComboBoxEx An extension of the combo box control that provides native support for item images.

Date and Time Picker

A simple and intuitive interface through which to exchange date and time information with a user.

Drag List Box A type of list box that enables the user to drag items from one position to another.

Edit A window within the user can view and edit text.

Flat Scroll Bar A scroll bar with a more customizable appearance than standard scroll bars.

Header A window that is usually positioned above columns of text or numbers. It contains a title for each column, and it can be divided into parts.

Hot Key A window that enables the user to enter a combination of keystrokes to be used as a hot key.

Image Lists A collection of images of the same size, each of which can be referred to by its index.

IP Address A window in which the user can enter an Internet Protocol (IP) address in an easily understood format.

List Box A simple list from which the user can select one or more items.

List-View A list box that provides several ways to arrange and display the items.

Month Calendar A calendar that enables the user to select a date or dates.

Pager A set of arrow buttons that enable the contents of a control window to be scrolled.

Progress Bar An animated control that indicates the progress of a lengthy operation.

Property Sheet A dialog box that enables the user to view and edit the properties of an item. Pages may be viewed as tabs, or in succession as a wizard.

ReBar A container for child windows. An application assigns child windows, which are often other controls, to a rebar control band.

Rich Edit A window in which the user can view and edit text with character and paragraph formatting. It can also contain embedded COM objects.

Scroll Bar A control that enables the user to choose the direction and distance to scroll information in a related window.

Static Non-interactive text, including labels for other controls.

Status Bar A horizontal window at the bottom of a parent window in which an application can display various kinds of status information.

SysLink A hypertext link.

Tab

A selectable page, analogous to a divider in a notebook. By using a tab control, an application can define multiple pages for the same area of a window or dialog box.

Task Dialog

A more powerful alternative to simple message boxes, incorporating elements such as custom buttons, radio buttons, hyperlinks, and progress bars.

Toolbar A window that contains one or more buttons and possibly other controls.

Tooltip A message that appears automatically when the mouse pointer hovers over a tool.

Trackbar A slider with optional tick marks, used to set a value within a range.

Tree-View A hierarchical list of items, such as the headings in a document or the files and directories on a disk.

Up-Down

A pair of arrow buttons that the user can click to increment or decrement a value, such as a scroll position or a number displayed in a companion control.

Class-Specific Information

Button Control Window Class

The button control's window class describes any type of button control. This includes command buttons, check boxes, and radio boxes. The button class style assigned to a button control determines what type of button it is.

The button control's window class is registered automatically when Windows starts. The name of the class is "BUTTON".

Styles BS_3STATE

The button is a check box which has three states: checked, grayed, and cleared.

BS_AUTO3STATE

The button is a check box which has three states: checked, grayed, and cleared. The button automatically changes its state when the user selects it.

BS_AUTOCHECKBOX

The button is a check box whose state toggles when the user selects it.

BS_AUTORADIOBUTTON

The button is a radio button whose state automatically changes to selected (and the state of all other radio buttons in the group to unselected) when the user selects it.

BS_BITMAP

The button displays a bitmap.

BS_BOTTOM

The button's text appears at the bottom of the button rectangle.

BS_CENTER

The button's text appears centered horizontally within the button rectangle.

BS_CHECKBOX

The button is a check box.

BS_DEFPUSHBUTTON

The button is the default push button in a dialog box, having a heavy black border.

BS_GROUPBOX

The window is a rectangular grouping frame in which other controls can be grouped.

BS_FLAT

The button is flat, not using the default 3D shading.

BS_ICON

The button displays an icon.

BS_LEFT

The text in the button rectangle is left-justified.

BS_LEFTTEXT, BS_RIGHTBUTTON

The radio or check box's text appears to the left of the button instead of to the right.

BS_MULTILINE

The button's text is wrapped across multiple lines if it cannot fit on a single line.

BS_NOTIFY

The button sends focus notification messages to its parent window.

BS_OWNERDRAW

The owner of the window is responsible for manually drawing it whenever it needs to be redrawn. This window style cannot be combined with any other button styles.

BS_PUSHBUTTON

The button is a push button.

BS_PUSHLIKE

The radio or check button takes on the appearance of a push button. A checked state makes the button look depressed; a cleared state makes the button look normal.

BS_RADIOBUTTON The button is a radio button.

BS_RIGHT

The text in the button rectangle is right-justified.

BS_TEXT

The button displays text.

BS_TOP

The text appears at the top of the button rectangle.

BS_USERBUTTON

Obsolete; use BS_OWNERDRAW instead.

BS_VCENTER

The text appears centered vertically within the button rectangle.

Constant Definitions

Const BS_3STATE = &H5 Const BS_AUTO3STATE = &H6 Const BS_AUTOCHECKBOX = &H3 Const BS_AUTORADIOBOX = &H9 Const BS_BITMAP = &H80 Const BS_BOTTOM = &H800 Const BS_CENTER = &H300 Const BS_CHECKBOX = &H2 Const BS_DEFPUSHBUTTON = &H1 Const BS_FLAT = &H8000

Const BS_GROUPBOX = &H7 Const BS_ICON = &H40 Const BS_LEFT = &H100 Const BS_LEFTTEXT = &H20 Const BS_MULTILINE = &H2000 Const BS_NOTIFY = &H4000 Const BS_OWNERDRAW = &HB Const BS_PUSHBUTTON = &H0 Const BS_PUSHLIKE = &H1000 Const BS_RADIOBUTTON = &H4

Const BS_RIGHT = &H200 Const BS_RIGHTBUTTON = &H20 Const BS_TEXT = &H0

Const BS_TOP = &H400 Const BS_USERBUTTON = &H8 Const BS_VCENTER = &HC00

Combo Box Control Window Class

The combo box control's window class describes an ordinary combo box control.

The button control's window class is registered automatically when Windows starts. The name of the class is "COMBOBOX".

Styles

CBS_AUTOHSCROLL

Automatically scroll text to the right when the user types a character at the end of the line.

CBS_DISABLENOSCROLL

Show a disable the vertical scroll bar in the drop-down list box if it does not contain enough items to scroll. If this flag is not specified, such a scroll bar is not displayed.

CBS_DROPDOWN

Display the list box whenever the user clicks the drop-down button.

CBS_DROPDOWNLIST

Display the list box whenever the user click the drop-down button, and do not allow the user to change the combo box's selection if the list is not dropped down.

CBS_HASSTRINGS

The combo box is drawn manually by the application and contains strings. Either

CBS_OWNERDRAWFICED or CBS_OWNERDRAWVARIABLE must also be specified.

CBS_LOWERCASE

Convert all text in the combo box to lowercase letters.

CBS_NOINTEGRALHEIGHT

Force the combo box to be exactly the size specified by the application, instead of allowing the operating system to slightly resize it to prevent displaying partial selections.

CBS_OEMCONVERT

Ensure that text in the combo box can readily be converted into the OEM character set.

CBS_OWNERDRAWFIXED

The owner of the combo box is fully responsible for drawing it manually, and all of the items in the combo box have the same height.

CBS_OWNERDRAWVARIABLE

The owner of the combo box is full responsible for drawing it manually, and the heights of the items in the combo box have can be different.

CBS_SIMPLE

Display the list box portion of the combo box at all times.

CBS_SORT

Automatically sort the strings added to the combo box.

CBS_UPPERCASE

Convert all text in the combo box to uppercase letters.

Constant Definitions

Const CBS_AUTOHSCROLL = &H40 Const CBS_DISABLENOSCROLL = &H800 Const CBS_DROPDOWN = &H2

Const CBS_DROPDOWNLIST = &H3 Const CBS_HASSTRINGS = &H200 Const CBS_LOWERCASE = &H4000

Const CBS_NOINTEGRALHEIGHT = &H400 Const CBS_OEMCONVERT = &H80

Const CBS_OWNERDRAWFIXED = &H10 Const CBS_OWNERDRAWVARIABLE = &H20 Const CBS_SIMPLE = &H1

Const CBS_SORT = &H100

Const CBS_UPPERCASE = &H2000

Edit Control Window Class

The edit control's window class descibes a regular text edit box.

The button control's window class is registered automatically when Windows starts. The name of the class is "EDIT".

Styles

ES_AUTOHSCROLL

Automatically scroll the text to the right when the user types a character at the end of the line.

When the user pressed ENTER, scroll the text all the way back to the left.

ES_AUTOVSCROLL

Automatically scroll the text back up when the user presses ENTER on the last line.

ES_CENTER

Center the text horizontally.

ES_LEFT

Left-align the text.

ES_LOWERCASE

Convert all the characters to lowercase as they are typed.

ES_MULTILINE

The edit control displays multiple lines of text. If this flag is not specified, it can only display a single line of text.

ES_NOHIDESEL

Do not hide the selected text in the edit control even if the control loses focus.

ES_NUMBER

Only allow digits to be entered into the edit control.

ES_OEMCONVERT

Ensure that text in the edit control can readily be converted into the OEM character set.

ES_PASSWORD

Display an asterisk for each character typed into the edit control. This cannot be used with ES_MULTILINE.

ES_READONLY

Do not allow the user to edit the text in the control.

ES_RIGHT

Right-align the text.

ES_UPPERCASE

Convert all the characters to uppercase as they are typed.

ES_WANTRETURN

Insert a carriage return into a multi-line edit control when the user pressed ENTER, instead of implementing the default behavior of ENTER.

Constant Definitions

Const ES_AUTOHSCROLL = &H80 Const ES_AUTOVSCROLL = &H40 Const ES_CENTER = &H1

Const ES_LEFT = &H0

Const ES_LOWERCASE = &H10 Const ES_MULTILINE = &H4 Const ES_NOHIDESEL = &H100 Const ES_NUMBER = &H2000 Const ES_OEMCONVERT = &H400 Const ES_PASSWORD = &H20 Const ES_READONLY = &H800 Const ES_RIGHT = &H2 Const ES_UPPERCASE = &H8

Const ES_WANTRETURN = &H1000

IP Address Control's Window Class

The IP Address control's window class describes an IP Address control. This control is similar to an edit control, but it is specialized for entering IP addresses in "dotted quad"

(a.b.c.d) format. The control performs bounds checking on all inputs, preventing the user from entering something that is not an IP address.

Before creating windows from this class, your program must first register it by calling InitCommonControlsEx with the appropriate parameters. The name of the class is

"SysIPAddress32".

Styles

None.

List Box Control Window Class

The list box control's window class describes an ordinary list box.

The button control's window class is registered automatically when Windows starts. The name of the class is "LISTBOX".

Styles

LBS_DISABLENOSCROLL

Show a disable the vertical scroll bar in the list box if it does not contain enough items to scroll. If this flag is not specified, such a scroll bar is not displayed.

LBS_EXTENDEDSEL

Allow the user to select multiple items.

LBS_HASSTRINGS

The list box is drawn manually by the application and contains strings. Either

LBS_OWNERDRAWFICED or LBS_OWNERDRAWVARIABLE must also be specified.

LBS_MULTICOLUMN

The list box contains multiple columns which are scrolled horizontally.

LBS_MULTIPLESEL

Toggle the selection of a string every time the user clicks or double-clicks it.

LBS_NODATA

Intended for list boxes having more than 1000 items, do not have the operating system handle any of the entries. LBS_OWNERDRAWFIXED must also be specified, and neither

LBS_SORT nor LBS_HASSTRINGS can be specified.

LBS_NOINTEGRALHEIGHT

Force the list box to be exactly the size specified by the application, instead of allowing the operating system to slightly resize it to prevent displaying partial selections.

LBS_NOREDRAW

Do not redraw the list box when changes are made.

LBS_NOSEL

Do not allow the user to select items in the list box.

LBS_NOTIFY

Notify the parent window whenever the user clicks or double-clicks a string in the list box.

LBS_OWNERDRAWFIXED

The owner of the list box is fully responsible for drawing it manually, and all of the items in the list box have the same height.

LBS_OWNERDRAWVARIABLE

The owner of the list box is full responsible for drawing it manually, and the heights of the items in the list box have can be different.

LBS_SORT

Automatically sort the strings in the list box alphabetically.

LBS_STANDARD

Automatically sort the strings in the list box alphabetically, notify the parent window whenever the user clicks or double-clicks a string, and display a border around the list box.

LBS_USETABSTOPS

Allow the list box to expand tab characters when drawing its strings.

LBS_WANTKEYBOARDINPUT

Notify the owner of the list box whenever the user types a key while the list box has the focus.

Constant Definitions

Const LBS_DISABLENOSCROLL = &H1000 Const LBS_EXTENDEDSEL = &H800 Const LBS_HASSTRINGS = &H40 Const LBS_MULTICOLUMN = &H200 Const LBS_MULTIPLESEL = &H8 Const LBS_NODATA = &H2000

Const LBS_NOINTEGRALHEIGHT = &H100 Const LBS_NOREDRAW = &H4

Const LBS_NOSEL = &H4000 Const LBS_NOTIFY = &H1

Const LBS_OWNERDRAWFIXED = &H10 Const LBS_OWNERDRAWVARIABLE = &H20

Const LBS_SORT = &H2

Const LBS_STANDARD = &HA00006 Const LBS_USETABSTOPS = &H80

Const LBS_WANTKEYBOARDINPUT = &H400

Scroll Bar Control Window Class

The scroll bar control's window class describes a standalone scroll bar (i.e., one that is not part of another control such as an edit control).

The button control's window class is registered automatically when Windows starts. The name of the class is "SCROLLBAR".

Styles

SBS_BOTTOMALIGM

Align the bottom edge of the scroll bar with the bottom edge of its rectangle, using its default height. SBS_HORZ must also be specified.

SBS_HORZ

The scroll bar is a horizontal scroll bar.

SBS_LEFTALIGN

Align the left edge of the scroll bar with the left edge of its rectangle, using its default width.

SBS_VERT must also be specified.

SBS_RIGHTALIGN

Align the right edge of the scroll bar with the right edge of its rectangle, using its default width. SBS_VERT must also be specified.

SBS_SIZEBOX

The scroll bar is a size box.

SBS_SIZEBOXBOTTOMRIGHTALIGN

Align the lower-right corner of the size box with the lower-right corner of its rectangle, using its default width and height. SBS_SIZEBOX must also be specified.

SBS_SIZEBOXTOPLEFTALIGN

Align the upper-left corner of the size box with the upper-left corner of its rectangle, using its default width and hieght. SBS_SIZEBOX must also be specified.

SBS_SIZEGRIP

The scroll bar is a size box with a raised edge.

SBS_TOPALIGN

Align the top edge of the scroll bar with the top edge of its rectangle, using its default height.

SBS_HORZ must also be specified.

SBS_VERT

The scroll bar is a vertical scroll bar.

Constant Definitions

Const SBS_BOTTOMALIGN = &H4 Const SBS_HORZ = &H0

Const SBS_LEFTALIGN = &H2 Const SBS_RIGHTALIGN = &H4 Const SBS_SIZEBOX = &H8

Const SBS_SIZEBOXBOTTOMRIGHTALIGN = &H4 Const SBS_SIZEBOXTOPLEFTALIGN = &H2 Const SBS_SIZEGRIP = &H10

Const SBS_TOPALIGN = &H2 Const SBS_VERT = &H1

Static Control Window Class

The static control's window class describes a static control. Static controls are commonly used as labels for other controls.

The button control's window class is registered automatically when Windows starts. The name of the class is "STATIC".

Styles SS_BITMAP

Display the bitmap specified by the static control's text.

SS_BLACKFRAME

Draw a frame around the static control in the same color as a window frame.

SS_BLACKRECT

Fill the static control with the same color as a window frame.

SS_CENTER

Center the text in the static control.

SS_CENTERIMAGE

If the bitmap or icon is smaller than the size of the static control, fill the rest of the control with whatever color is at the image's upper-left corner.

SS_ENDELLIPSIS

Windows NT, 2000: Replace the end of the string with an ellipsis if it is too long to fit in the static control.

SS_ENHMETAFILE

Display the enhanced metafile identified by the static control's text. Scale the enhanced metafile to fit the static control.

SS_ETCHEDFRAME

Draw the frame of the static control using the etched edge style.

SS_ETCHEDHORZ

Draw only the top and bottom edges of the static control using the etched edge style.

SS_ETCHEDVERT

Draw only the left and right edges of the static control using the etched edge style.

SS_GRAYFRAME

Draw a frame around the static control in the same color as the screen background.

Draw a frame around the static control in the same color as the screen background.

In document Win32_API_tutorials (Page 107-121)