A style affects the appearance and behavior of a window. Each window class has styles that are encapsulated in style objects.
Generic styles are defined in IWindow. Classes derived from IWindow can combine their own styles with those of IWindow.
Each window class maintains its own default style object. You can access default style objects using the static member function defaultStyle and then set it using the static member function setDefaultStyle. Each window class also maintains a style object called classDefaultStyle that corresponds to the initial setting of defaultStyle.
Most window classes provide one or more constructors that
accept a style object as one parameter. You can only construct a
style object from existing style objects. These style objects are
only used by window constructors. The style of a window can
subsequently be changed and queried using the window class member
functions. Also, some styles cannot change after a window has
been created, in which case, no member function is provided to
change the style.
The following sections describe how you can use bitwise
operators. For the sake of simplicity, the IComboBox class and
its styles are used for all examples. The IBitFlag class provides
bitwise operators that you can use with
the styles of the Open Class Library just as if you
were using them with numbers. Refer to IComboBox in the Reference
Information for more information about this class and its
styles.
The assignment operator (=) returns one style object that is set equal to the specified style object. The value of the resulting object is equal to the value of the operand object. For example:
IComboBox::Style myStyle = IComboBox::dropDownType;
The bitwise OR (|) operator returns a style object that is a combination of two or more style objects. The value of the resulting object is the bitwise OR of the value of the two operand objects.
You can combine any existing style objects, such as myStyle1 and myStyle2 in the following example, to create yet another style object. For example:
IComboBox::Style myStyle3 = myStyle1 | myStyle2;
This example adds the tabStop style to the myStyle object:
IComboBox::Style myStyle = IComboBox::dropDownType; myStyle |= IWindow::tabStop;
In many cases, you can combine styles of one class with those of another class. Here, an IComboBox style is combined with an IWindow style. The documentation for each class that has styles specifies whether other classes have compatible styles that you can use when constructing objects for those classes.
The bitwise AND (&) operator returns an unsigned long integer that identifies if there are any bits common to the operand style or attribute objects. Typically, you use this operator to test whether a bitwise OR (|) operator has been used to combine one style object with another. For example:
bool isADropDown = false; if (myStyle1 & IComboBox::dropDownType) isADropDown = true;
The bitwise NOT (~) operator returns a negated style object.
The
value of the resulting object is the bitwise NOT of the value of
the operand object. For example:
IComboBox::Style::NegatedStyle negatedStyle = ~myStyle;
This code returns an object named negatedStyle that negates the value of the myStyle object.
The precedence of the AND operator (&) is greater than the OR operator (|). You must be aware of operator precedence to avoid creating invalid styles that might not be obvious.
Note: | If you do not want to consider operator precedence, specify the styles you want instead of negating others from the default Open Class Library styles. |
The following example creates an invalid style that the IViewPort constructor will reject. This causes the following:
IViewPort::defaultStyle() | IViewPort::alwaysHorizontalScrollBar & ~IViewPort::asNeededHorizontalScrollBar
to be evaluated as:
IViewPort::defaultStyle() | (IViewPort::alwaysHorizontalScrollBar & ~IViewPort::asNeededHorizontalScrollBar)
as opposed to the following:
(IViewPort::defaultStyle() | IViewPort::alwaysHorizontalScrollBar) & ~IViewPort::asNeededHorizontalScrollBar
Therefore, you must consider the order and the operator precedence when you negate a style because the Open Class Library cannot change the order in which operators are evaluated in the code statement.
You can create a window with a specific style in the following ways:
This example shows how to create an entry field control with a style that is a combination of styles from IWindow and IEntryField:
IEntryField entryField( ID_EF1, parent, owner, IRectangle(10, 10, 100, 20), IWindow::visible | IWindow::tabStop | IWindow::group | IEntryField::margin | IEntryField::autoScroll );
Alternatively, you can explicitly construct the style object and pass it as a parameter as follows:
IEntryField::Style efStyle = IWindow::visible | IWindow::tabStop | IWindow::group | IEntryField::margin | IEntryField::autoScroll ; IEntryField entryField( ID_EF1, parent, owner, IRectangle(10, 10, 100, 20), efStyle );
You can also access the default style object using the static member function defaultStyle. This simplifies the preceding example to the following:
IEntryField entryField( ID_EF1, parent, owner, IRectangle(10, 10, 100, 20), IEntryField::defaultStyle() | IWindow::tabStop | IWindow::group );
IEntryField::Style efStyle = IEntryField::defaultStyle() | IWindow::tabStop | IWindow::group ; IEntryField::setDefaultStyle(efStyle); IEntryField entryField( ID_EF1, parent, owner, IRectangle(10, 10, 100, 20) );
IEntryField entryField( ID_EF1, parent, owner, IRectangle(10, 10, 100, 20) ); entryField.enableGroup(); // Member function of IWindow entryField.enableTabStop(); // Member function of IWindow entryField.enableAutoScroll(); // Member function of IEntryField
Creating a Frame Window
Using Cursor Classes