20 November, 2008 § Leave a Comment
Aligning text in an MFC application dialog can be done in many ways. I’ve seen some that calculate the width of the text it is going to print and then recalculate the CRect that the text should be placed it to give it the look of being aligned.
Today I was trying to do just that and was looking through the MSDN documentation for the different method calls when I stumbled upon CDC::SetTextAlign. The MSDN documentation reads:
UINT SetTextAlign( UINT nFlags );
TA_RIGHT Aligns the point with the right side of the bounding rectangle.
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.
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. The rectangle that bounds the text is defined by the adjacent character cells in the text string. The nFlags 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: