Bewerken

Delen via


CMFCFontComboBox Class

The CMFCFontComboBox class creates a combo box control that contains a list of fonts.

Syntax

class CMFCFontComboBox : public CComboBox

Members

Public Constructors

Name Description
CMFCFontComboBox::CMFCFontComboBox Constructs a CMFCFontComboBox object.
CMFCFontComboBox::~CMFCFontComboBox Destructor.

Public Methods

Name Description
CMFCFontComboBox::CompareItem Called by the framework to determine the relative position of a new item in the sorted list box of the current font combo box control. (Overrides CComboBox::CompareItem.)
CMFCFontComboBox::DrawItem Called by the framework to draw a specified item in the current font combo box control. (Overrides CComboBox::DrawItem.)
CMFCFontComboBox::GetSelFont Retrieves information about the currently selected font.
CMFCFontComboBox::MeasureItem Called by the framework to inform Windows of the dimensions of the list box in the current font combo box control. (Overrides CComboBox::MeasureItem.)
CMFCFontComboBox::PreTranslateMessage Translates window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions. (Overrides CWnd::PreTranslateMessage.)
CMFCFontComboBox::SelectFont Selects the font that matches the specified criteria from the font combo box.
CMFCFontComboBox::Setup Initializes the list of items in the font combo box.

Data Members

Name Description
CMFCFontComboBox::m_bDrawUsingFont Indicates to the framework which font to use to draw the item labels in the current font combo box.

Remarks

To use a CMFCFontComboBox object in a dialog box, add a CMFCFontComboBox variable to the dialog box class. Then in the OnInitDialog method of the dialog box class, call the CMFCFontComboBox::Setup method to initialize the list of items in the combo box control.

Inheritance Hierarchy

CObject

CCmdTarget

CWnd

CComboBox

CMFCFontComboBox

Requirements

Header: afxfontcombobox.h

CMFCFontComboBox::CMFCFontComboBox

Constructs a CMFCFontComboBox object.

CMFCFontComboBox();

Return Value

Remarks

CMFCFontComboBox::GetSelFont

Retrieves information about the currently selected font.

CMFCFontInfo* GetSelFont() const;

Return Value

A pointer to CMFCFontInfo Class object that describes a font. It can be NULL if no font is selected in the combo box.

Remarks

CMFCFontComboBox::m_bDrawUsingFont

Indicates to the framework which font to use to draw the item labels in the current font combo box.

static BOOL m_bDrawUsingFont;

Remarks

Set this member to TRUE to direct the framework to use the same font to draw each item label. Set this member to FALSE to direct the framework to draw each item label with the font whose name is the same as the label. The default value of this member is FALSE.

CMFCFontComboBox::SelectFont

Selects the font that matches the specified criteria from the font combo box.

BOOL SelectFont(CMFCFontInfo* pDesc);

BOOL SelectFont(
    LPCTSTR lpszName,
    BYTE nCharSet=DEFAULT_CHARSET);

Parameters

pDesc
[in] Points to a font description object.

lpszName
[in] Specifies a font name.

nCharSet
[in] Specifies a character set. The default value is DEFAULT_CHARSET. For more information, see the lfCharSet member of the LOGFONT structure.

Return Value

TRUE if an item in the font combo box matches the specified font description object or font name and charset; otherwise, FALSE.

Remarks

Use this method to select and scroll to the item in the font combo box that corresponds to the specified font.

Example

The following example demonstrates how to use the SelectFont method in the CMFCFontComboBox class. This example is part of the New Controls sample.

CMFCFontComboBox m_wndFont;
m_wndFont.SelectFont(_T("Arial"));

CMFCFontComboBox::Setup

Initializes the list of items in the font combo box.

BOOL Setup(
    int nFontType=DEVICE_FONTTYPE|RASTER_FONTTYPE|TRUETYPE_FONTTYPE,
    BYTE nCharSet=DEFAULT_CHARSET,
    BYTE nPitchAndFamily=DEFAULT_PITCH);

Parameters

nFontType
[in] Specifies the font type. The default value is the bitwise combination (OR) of DEVICE_FONTTYPE, RASTER_FONTTYPE, and TRUETYPE_FONTTYPE.

nCharSet
[in] Specifies the font character set. The default value is DEFAULT_CHARSET.

nPitchAndFamily
[in] Specifies the font pitch and family. The default value is DEFAULT_PITCH.

Return Value

TRUE if the font combo box was initialized successfully; otherwise, FALSE.

Remarks

This method initializes the font combo box by enumerating the currently installed fonts that match the specified parameters and inserting those font names in the font combo box.

Example

The following example demonstrates how to use the Setup method in the CMFCFontComboBox class. This example is part of the New Controls sample.

CMFCFontComboBox m_wndFont;
// specify the font type
// BOOL m_bTrueType: true font type
// BOOL m_bRaster: raster font type
// BOOL m_bDeviceFont: device font type
int nFontType = 0;

if (m_bTrueType)
{
   nFontType |= TRUETYPE_FONTTYPE;
}

if (m_bRaster)
{
   nFontType |= RASTER_FONTTYPE;
}

if (m_bDeviceFont)
{
   nFontType |= DEVICE_FONTTYPE;
}

CWaitCursor wait;
m_wndFont.Setup(nFontType);

See also

Hierarchy Chart
Classes
CMFCToolBarFontComboBox Class
CMFCFontInfo Class