Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls


The crTextColor variable is used to set the color for the text.

The bCharSet variable is used to the character set value as defined for the Win32's
LOGFONT structure.

The bPitchAndFamily member variable is the same as set for the LOGFONT structure.

The szFaceName variable is used to specify the name of the font to apply to the text.

If you want to find out what formatting is applied on a character or text, call the
CRichEditCtrl::GetSelectionCharFormat() method. Its syntax is:

DWORD GetSelectionCharFormat(CHARFORMAT& cf) const;

This method returns the type of dwMask of the CHARFORMAT structure applied on
the character or text.

To control the alignment of a paragraph on a right edit control, you can call the
CRichEditCtrl::SetParaFormat() method. Its syntax is:

BOOL SetParaFormat(PARAFORMAT& pf);

The actual paragraph formatting is set using the Win32 API's PARAFORMAT structure.
It is created as follows:

typedef struct _paraformat {
UINT cbSize;
DWORD dwMask;
WORD wNumbering;
WORD wReserved;
LONG dxStartIndent;
LONG dxRightIndent;
LONG dxOffset;
WORD wAlignment;
SHORT cTabCount;
LONG rgxTabs[MAX_TAB_STOPS];
} PARAFORMAT;

To define the necessary values for this structure, first declare a variable from it and
retrieve its size. This is done with the cbSize member variable. Secondly, use the dwMask
member variable to specify what formatting you want to perform. For example, to control
paragraph alignment, initialize dwMask with PFM_ALIGNMENT. On the other hand, if
you want to set or remove a bullet on a paragraph, initialize the dwMask variable with
PFM_NUMBERING.

The wNumbering member variable is used to apply or remove the bullet from a
paragraph.

You will need to use wReserved. Therefore, you can either ignore it or set its value to 0.

The dxStartIndent, the dxRightIndent, and the dxOffset member variables are used to
indent text.

If you had initialized dwMask with PFM_ALIGNMENT, you can use wAlignment to
specify the alignment of the paragraph. The possible values are:
Free download pdf