SetTextAlign

2.x

  UINT SetTextAlign(hdc, fuAlign)    
  HDC hdc; /* handle of device context */
  UINT fuAlign; /* text-alignment flags, */  

The SetTextAlign function sets the text-alignment flags for the given device context.

Parameters

hdc

Identifies the device context.

fuAlign

Specifies text-alignment flags. The flags specify the relationship between a point and a rectangle that bounds the text. The point can be either the current position or coordinates specified by a text-output function (such as the ExtTextOut function). The rectangle that bounds the text is defined by the adjacent character cells in the text string.

The fuAlign parameter can be one or more flags from the following three categories. Choose only one flag from each category.

The first category affects text alignment in the x-direction:

Value Meaning

TA_CENTER Aligns the point with the horizontal center of the bounding rectangle.
TA_LEFT Aligns the point with the left side of the bounding rectangle. This is the default setting.
TA_RIGHT Aligns the point with the right side of the bounding rectangle.

The second category affects text alignment in the y-direction:

Value Meaning

TA_BASELINE Aligns the point with the base line of the chosen font.
TA_BOTTOM Aligns the point with the bottom of the bounding rectangle.
TA_TOP Aligns the point with the top of the bounding rectangle. This is the default setting.

The third category determines whether the current position is updated when text is written:

Value Meaning

TA_NOUPDATECP Does not update the current position after each call to a text-output function. This is the default setting.
TA_UPDATECP Updates the current x-position after each call to a text-output function. The new position is at the right side of the bounding rectangle for the text. When this flag is set, the coordinates specified in calls to the TextOut function are ignored.

Return Value

The return value is the previous text-alignment settings, if the function is successful. The low-order byte contains the horizontal setting; the high-order byte contains the vertical setting. Otherwise, the return value is zero.

Comments

The text-alignment flags set by SetTextAlign are used by the TextOut and ExtTextOut functions.

Example

The following example uses the GetTextFace function to retrieve the name of the current typeface, calls SetTextAlign so that the current position is updated when the TextOut function is called, and then writes some introductory text and the name of the typeface by calling TextOut:

int nFaceNameLen;
char aFaceName[80];

nFaceNameLen = GetTextFace(hdc, /* returns length of string */
    sizeof(aFaceName),       /* size of face-name buffer    */
    (LPSTR) aFaceName);      /* address of face-name buffer */

SetTextAlign(hdc,
    TA_UPDATECP);         /* updates current position       */
MoveTo(hdc, 100, 100);    /* sets current position          */
TextOut(hdc, 0, 0,        /* uses current position for text */
    "This is the current face name: ", 31);
TextOut(hdc, 0, 0, aFaceName, nFaceNameLen);

See Also

ExtTextOut, GetTextAlign, TextOut