GetTextAlign

2.x

  UINT GetTextAlign(hdc)    
  HDC hdc; /* handle of device context */

The GetTextAlign function retrieves the status of the text-alignment flags for the given device context.

Parameters

hdc

Identifies the device context.

Return Value

The return value specifies the status of the text-alignment flags. This parameter can be one or more of the following values:

Value Meaning

TA_BASELINE Specifies alignment of the x-axis and the base line of the chosen font within the bounding rectangle.
TA_BOTTOM Specifies alignment of the x-axis and the bottom of the bounding rectangle.
TA_CENTER Specifies alignment of the y-axis and the center of the bounding rectangle.
TA_LEFT Specifies alignment of the y-axis and the left side of the bounding rectangle.
TA_NOUPDATECP Specifies that the current position is not updated.
TA_RIGHT Specifies alignment of the y-axis and the right side of the bounding rectangle.
TA_TOP Specifies alignment of the x-axis and the top of the bounding rectangle.
TA_UPDATECP Specifies that the current position is updated.

Comments

The text-alignment flags retrieved by the GetTextAlign function are used by the TextOut and ExtTextOut functions. These flags determine how TextOut and ExtTextOut align a string of text in relation to the string's starting point.

The text-alignment flags are not necessarily single-bit flags and may be equal to zero. To test whether a flag is set, an application should follow three steps:

1.Apply the bitwise OR operator to the flag and its related flags.

Following are the groups of related flags:

TA_LEFT, TA_CENTER, and TA_RIGHT

TA_BASELINE, TA_BOTTOM, and TA_TOP

TA_NOUPDATECP and TA_UPDATECP

2.Apply the bitwise AND operator to the result and the return value of the GetTextAlign function.

3.Test for the equality of this result and the flag.

Example

The following example uses the method described in the preceding Comments section to determine whether text is aligned at the right, left, or center of the bounding rectangle. If the TA_RIGHT flag is set, the SetTextAlign function is used to set the text alignment to the left side of the rectangle.

switch ((TA_LEFT | TA_CENTER | TA_RIGHT) & GetTextAlign(hdc)) {
    case TA_RIGHT:
        TextOut(hdc, 200, 100, "This is TA_RIGHT.", 17);
        SetTextAlign(hdc, TA_LEFT);
        TextOut(hdc, 200, 120, "This is TA_LEFT.", 16);
        break;
    case TA_LEFT:
        .
        .
        .
    case TA_CENTER:
        .
        .
        .
}

See Also

ExtTextOut, SetTextAlign, TextOut