Adds the names of the available fonts to the combo box control.
C
LONG WINAPI SftBox_Fonts(HWND hwndCtl, LONG index, BOOL fBitmaps, HDC hDCParm, int type);
C++
LONG CSftBox::Fonts(LONG index, BOOL fBitmaps, HDC hDCParm, int type);
hwndCtl
The window handle of the combo box control.
index
Specify -1 to add the font names following the items already in the combo box. Otherwise, index is the zero-based index of an existing item. The font names are inserted in front of this item.
fBitmaps
Set to TRUE to add an item picture describing the font type to each item. Set to FALSE if no item pictures are desired; the items added then have no item picture.
hDCParm
The device context of an output device, typically a printer, whose fonts are to be added. This parameter may be NULL, in which case the fonts of the display are added.
type
Defines the fonts to add. Type can be SFTBOX_FONT_ALL or a combination of the following values:
| SFTBOX_FONT_FIXED | Fixed pitch fonts are included. |
| SFTBOX_FONT_VAR | Variable pitch fonts are included. |
| SFTBOX_FONT_TT | TrueType fonts (this includes OpenType fonts) are included. |
| SFTBOX_FONT_RS | Raster fonts are included. |
| SFTBOX_FONT_VC | Vector fonts are included. |
| SFTBOX_FONT_DISPLAY | The fonts of the display are added in addition to the fonts of the device context hDCParm. The fonts of the display are always added if hDCParm is NULL. |
| SFTBOX_FONT_ALL | All fonts are included. This value combines all of the above. |
The return value is the number of items added to the combo box. -1 is returned if index is not valid.
The Fonts function adds the names of the available fonts to the combo box control.
One item is added for each font. The text of the first column (column 0) is the font name (typeface name). Each font name is added only once, even if the font is available for the display and for the device context hDCParm. Only the names added by the same call are checked for duplicates; items that were already in the combo box are not searched, so calling Fonts again adds the font names again. The font names are added in the order in which Windows enumerates the fonts, not in a particular order. The items can be sorted using SortItems or SortItemsEx.
A font is added only if it matches type. A font is tested twice, once for its pitch (SFTBOX_FONT_FIXED, SFTBOX_FONT_VAR) and once for its technology (SFTBOX_FONT_TT, SFTBOX_FONT_RS, SFTBOX_FONT_VC), so at least one value of each group must be specified. For example, SFTBOX_FONT_FIXED | SFTBOX_FONT_TT adds fixed pitch TrueType fonts only. SFTBOX_FONT_VAR | SFTBOX_FONT_FIXED | SFTBOX_FONT_TT adds all TrueType fonts.
If fBitmaps is TRUE, the item picture of each item (see SetItemBitmap) describes the font type. SftBox/DLL provides pictures for TrueType fonts, OpenType fonts and device fonts (fonts provided by the output device, such as a printer). Other fonts do not have an item picture. The pictures are owned by the combo box and remain valid until the combo box is destroyed.
The font type of each font is saved as cell data of the first column. It can be retrieved using GetCellInfo (SFTBOX_CELL, cellData). The value is the font type reported by Windows, a combination of RASTER_FONTTYPE, DEVICE_FONTTYPE and TRUETYPE_FONTTYPE. SFTBOX_OPENTYPE_FONTTYPE is added for OpenType fonts. A vector font has neither RASTER_FONTTYPE nor TRUETYPE_FONTTYPE.
The Fonts function does not remove existing items. Use ResetContent to remove all items before adding the font names. If the dropdown portion is shown, it is hidden.
Once a font name has been selected by the user, the FontStyles and FontSizes functions can be used to add the available styles and sizes of this font to other combo boxes.
#include "resource.h" // application resources /**********************************************************************/ /* Globals */ /**********************************************************************/ HINSTANCE g_hInst; // App Instance Handle HWND m_hwndFonts; // Fonts - SftBox combo box control HWND m_hwndStyle; // Font styles - SftBox combo box control HWND m_hwndSizes; // Font sizes - SftBox combo box control HDC m_hDC; // Current printer HGLOBAL m_hDevMode; HGLOBAL m_hDevNames; int m_SizeSelected = 10; // last explicitly selected font size
void CMainDlg::AddFonts()
{
// clear (in case of refresh)
m_Fonts.ResetContent();
// Add the font names, with a picture for the font type. Without a
// printer, the fonts of the display are added.
m_Fonts.Fonts(-1, TRUE, m_hDC, SFTBOX_FONT_ALL);
// Get the default font height
TEXTMETRIC tm;
{
CClientDC dc(&m_Fonts);
dc.GetTextMetrics(&tm);
}
See Also C/C++ API | Categories | Notifications