Adds the available styles of a font to the combo box control.
C
BOOL WINAPI SftBox_FontStyles(HWND hwndCtl, HDC hDCParm, LPCTSTR lpszFont, LPCTSTR lpszStyles, LPCTSTR lpszItalic);
C++
BOOL CSftBox::FontStyles(HDC hDCParm, LPCTSTR lpszFont, LPCTSTR lpszStyles, LPCTSTR lpszItalic);
hwndCtl
The window handle of the combo box control.
hDCParm
The device context of an output device, typically a printer. The styles available for this device are added in addition to the styles available for the display. This parameter may be NULL, in which case only the styles available for the display are added.
lpszFont
The font name (typeface name) of the font whose styles are to be added.
lpszStyles
A string with the names of the font weights, separated by commas. The string contains nine names, for the weights thin (FW_THIN), extra light (FW_EXTRALIGHT), light (FW_LIGHT), normal (FW_NORMAL), medium (FW_MEDIUM), semibold (FW_SEMIBOLD), bold (FW_BOLD), extra bold (FW_EXTRABOLD) and heavy (FW_HEAVY), in this order. This parameter may be NULL, in which case the string "Normal,Normal,Normal,Normal,Bold,Bold,Bold,Bold,Bold" is used.
lpszItalic
The string that is appended to the name of the font weight to describe an italic style. This parameter may be NULL, in which case the string ", Italic" is used.
The return value is TRUE if the combo box contains at least one item once the styles have been added, otherwise FALSE is returned.
The FontStyles function adds the available styles of a font to the combo box control.
One item is added for each style. The text of the first column (column 0) is the name of the font weight, taken from lpszStyles, followed by lpszItalic for an italic style (for example "Bold, Italic"). If a font weight is not one of the nine weights described by lpszStyles, the nearest weight is used. If lpszStyles has no name for a weight, the name "Normal" and the weight FW_NORMAL are used.
The style is saved as cell data of the first column. It can be retrieved using GetCellInfo (SFTBOX_CELL, cellData). The value is the font weight (FW_NORMAL, FW_BOLD, etc.). For an italic style, the value 0x80000000 is added.
The styles are added in ascending order of their font weight. A style is added only once. A style is also not added if another item with the same text already exists. With the default names, where several font weights share one name, the combo box contains at most the styles "Normal", "Normal, Italic", "Bold" and "Bold, Italic".
For a vector font, the styles normal, normal italic, bold and bold italic are added.
The FontStyles function does not remove existing items. Use ResetContent to remove all items before adding the styles of another font.
The Fonts function adds the available font names to a combo box. The FontSizes function adds the available sizes of a font.
// get the current style
GetWindowText(m_hwndStyle, szBuffer, sizeof(szBuffer)/sizeof(szBuffer[0]));
// clear (in case of refresh)
SftBox_ResetContent(m_hwndStyle);
// Add font styles
SftBox_FontStyles(m_hwndStyle, m_hDC, lpszFont, NULL, NULL);
// Select the previous style if possible
if (SftBox_SelectStringExact(m_hwndStyle, -1, 0, szBuffer, FALSE) < 0)
SftBox_SetCurSel(m_hwndStyle, 0);
SftBox_RecalcHorizontalExtent(m_hwndStyle, -1);
}
// get the current style
CString style;
m_Style.GetWindowText(style);
// clear (in case of refresh)
m_Style.ResetContent();
// Add font styles
m_Style.FontStyles(m_hDC, lpszFont, NULL, NULL);
// Select the previous style if possible
if (m_Style.SelectStringExact(-1, 0, style, FALSE) < 0)
m_Style.SetCurSel(0);
m_Style.RecalcHorizontalExtent(-1);
}See Also C/C++ API | Categories | Notifications