The GetCommDlgFont function retrieves the currently selected font from the common dialog box. This function is no longer supported and may not be available in future versions of Windows. Applications should use the ChooseFont function instead.
[in]
HWND: Handle to the owner window of the dialog box.
[out]
LPCHOOSEFONT: Pointer to a CHOOSEFONT
structure that contains information about the font selected in the dialog box.
If the function succeeds, the return value is a nonzero value. If the function fails, the return value is zero.
The GetCommDlgFont function is intended to be called after a font common dialog box has been displayed and the user has selected a font. The function fills the provided CHOOSEFONT
structure with the details of the selected font.
It is strongly recommended to use the ChooseFont function for displaying font selection dialogs as it provides a more modern and robust interface.
This function is obsolete and should not be used in new development. Use ChooseFont instead.
// This is a conceptual example and is not recommended for new development. // Use ChooseFont instead. #include <windows.h> int DisplayObsoleteFontDialog(HWND hwndOwner) { CHOOSEFONT cf; LOGFONT lf; BOOL bSuccess; // Initialize CHOOSEFONT structure ZeroMemory(&cf, sizeof(cf)); cf.lStructSize = sizeof(cf); cf.hwndOwner = hwndOwner; cf.lpLogFont = &lf; cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT; // Call the obsolete function (for demonstration only) bSuccess = GetCommDlgFont(hwndOwner, &cf); if (bSuccess) { // Font selection was successful. // You can now use the font information in lf. // For example, create a font object for rendering. // HFONT hFont = CreateFontIndirect(&lf); // ... use hFont ... // DeleteObject(hFont); return 1; // Success } else { // User canceled or an error occurred. return 0; // Failure } }