description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CMFCToolBarFontComboBox Class |
CMFCToolBarFontComboBox Class |
11/04/2016 |
|
|
25f8e08c-aadd-4cb5-9581-a99d49d444b1 |
A toolbar button that contains a combo box control that enables the user to select a font from a list of system fonts.
class CMFCToolBarFontComboBox : public CMFCToolBarComboBoxButton
Name | Description |
---|---|
CMFCToolBarFontComboBox::CMFCToolBarFontComboBox | Constructs a CMFCToolBarFontComboBox object. |
Name | Description |
---|---|
CMFCToolBarFontComboBox::GetFontDesc | Returns a pointer to the CMFCFontInfo object for a specified index in the combo box. |
CMFCToolBarFontComboBox::SetFont | Selects a font in the font combo box according to either the name of the font, or the prefix and character set of the font. |
CMFCToolBarFontComboBox::m_nFontHeight
The height of the characters in the font combo box.
To add a font combo box button to a toolbar, follow these steps:
-
Reserve a dummy resource ID for the button in the parent toolbar resource.
-
Construct a
CMFCToolBarFontComboBox
object. -
In the message handler that processes the AFX_WM_RESETTOOLBAR message, replace the original button with the new combo box button by using CMFCToolBar::ReplaceButton.
-
Synchronize the font that is selected in the combo box with the font in the document by using the CMFCToolBarFontComboBox::SetFont method.
To synchronize the document's font with the font selected in the combo box, use the CMFCToolBarFontComboBox::GetFontDesc method to retrieve the attributes of the selected font, and use those attributes to create a CFont Class object.
The font combo box button calls the Win32 function EnumFontFamiliesEx to determine the screen and printer fonts available to the system.
Header: afxtoolbarfontcombobox.h
Constructs a CMFCToolBarFontComboBox object.
public:
CMFCToolBarFontComboBox(
UINT uiID,
int iImage,
int nFontType = DEVICE_FONTTYPE | RASTER_FONTTYPE | TRUETYPE_FONTTYPE,
BYTE nCharSet = DEFAULT_CHARSET,
DWORD dwStyle = CBS_DROPDOWN,
int iWidth = 0,
BYTE nPitchAndFamily = DEFAULT_PITCH);
protected:
CMFCToolBarFontComboBox(
CObList* pLstFontsExternal,
int nFontType,
BYTE nCharSet,
BYTE nPitchAndFamily);
CMFCToolBarFontComboBox();
uiID
[in] The command ID of the combo box.
iImage
[in] The zero-based index of a toolbar image. The image is located in the CMFCToolBarImages Class object that CMFCToolBar Class class maintains.
nFontType
[in] The types of fonts that the combo box contains. This parameter can be a combination (boolean OR) of the following values:
DEVICE_FONTTYPE
RASTER_FONTTYPE
TRUETYPE_FONTTYPE
nCharSet
[in] If set to DEFAULT_CHARSET, the combo box contains all uniquely-named fonts in all character sets. (If there are two fonts with the same name, the combo box contains one of them.) If set to a valid character set value, the combo box contains only fonts in the specified character set. See LOGFONT for a listing of possible character sets.
dwStyle
[in] The style of the combo box. (see Combo-Box Styles)
iWidth
[in] The width in pixels of the edit control.
nPitchAndFamily
[in] If set to DEFAULT_PITCH, the combo box contains fonts regardless of pitch. If set to FIXED_PITCH or VARIABLE_PITCH, the combo box contains only fonts with that pitch type. Filtering based on font family is not currently supported.
pLstFontsExternal
[out] Pointer to a CObList Class object that stores the available fonts.
Usually, CMFCToolBarFontComboBox
objects store the list of available fonts in a single shared CObList
object. If you use the second overload of the constructor and provide a valid pointer to pLstFontsExternal, that CMFCToolBarFontComboBox
object will instead fill the CObList
that pLstFontsExternal points to with available fonts.
The following example demonstrates how to construct a CMFCToolBarFontComboBox
object. This code snippet is part of the Word Pad sample.
[!code-cppNVC_MFC_WordPad#7]
Returns a pointer to the CMFCFontInfo
object for a specified index in the combo box.
const CMFCFontInfo* GetFontDesc(int iIndex=-1) const;
iIndex
[in] Specifies the zero-based index of a combo box item.
A pointer to a CMFCFontInfo
object. If iIndex does not specify a valid item index, the return value is NULL.
Specifies the height, in pixels, of characters in the font combo box if the combo box has owner draw style.
static int m_nFontHeight
If the m_nFontHeight
variable is 0, the height is calculated automatically according to the default font of the combo box. The height includes both the ascent of characters above the baseline and the descent of characters underneath the baseline.
Selects the font in the font combo box according to the font name and character set that are specified in the parameters.
BOOL SetFont(
LPCTSTR lpszName,
BYTE nCharSet=DEFAULT_CHARSET,
BOOL bExact=FALSE);
lpszName
[in] Specifies the font name or prefix.
nCharSet
[in] Specifies the character set.
bExact
[in] Specifies whether lpszName contains the font name or the font prefix.
Nonzero if the font was selected successfully; otherwise 0.
If bExact is TRUE, this method selects a font that exactly matches the name that you specified as lpszName. If bExact is FALSE, this method selects a font that starts with the text specified as lpszName and that uses the character set that you specified as nCharSet. If nCharSet is set to DEFAULT_CHARSET, the character set will be ignored and only lpszName will be used to select a font.
Hierarchy Chart
Classes
CMFCToolBar Class
CMFCToolBarButton Class
CMFCToolBarComboBoxButton Class
CMFCFontInfo Class
CMFCToolBar::ReplaceButton
Walkthrough: Putting Controls On Toolbars