OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
Using font common dialog boxes

The font common dialog box lets you choose a font to use in your application, including the typeface, size, style, and so on.

For example, a word processor might use the font common dialog box to choose the font for a paragraph. TChooseFontDialog::TData has several members you must initialize before constructing the dialog box object:

TData memberTypeDescription
DCHDCA handle to the device context of the printer whose fonts you want to select, if you specify CF_PRINTERFONTS in Flags. Otherwise ignored.
LogFontLOGFONTA handle to a LOGFONT that specifies the font's appearance. When you execute the dialog box and specify the flag CF_INITTOLOGFONTSTRUCT, the dialog box appears with the specified font (or the closest possible match) as the default. When the user closes the dialog box, LogFont is filled with the selections the user made.
PointSizeintThe point size of the selected font (in tenths of a point). On input, it sets the size of the default font. On output, it returns the size the user selected.
ColorTColorThe color of the selected font, if the CF_EFFECTS flag is set. On input, it sets the color of the default font. On output, it holds the color the user selected.
Stylechar far*Lets you specify the style of the dialog.
FontTypeuint16A set of flags describing the styles of the selected font. Set only on output.
SizeMinint Specifies the minimum and maximum Point sizes (in tenths of a point) the user can select, if the CF_LIMITSIZE flag is set.
SizeMaxint

In this example, a font common dialog box is used to set the window object's Font member, which is used elsewhere to paint text in the window. Note how a new font object is constructed using TFont.

void TCommDlgWnd::CmFont()
{
TChooseFontDialog::TData FontData;
FontData.DC = 0;
FontData.Color = Color;
FontData.Style = 0;
FontData.SizeMin = 0;
FontData.SizeMax = 0;
if (TChooseFontDialog(this, FontData).Execute() == IDOK) {
delete Font;
Color = FontData.Color;
Font = new TFont(&FontData.LogFont);
}
Invalidate();
}

See Also