GetCommDlgFont

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.

BOOL GetCommDlgFont(
    HWND hwndOwner,
    LPCHOOSEFONT lpcf
);

Parameters

Return Value

If the function succeeds, the return value is a nonzero value. If the function fails, the return value is zero.

Remarks

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.

Important

This function is obsolete and should not be used in new development. Use ChooseFont instead.

See Also

Example (Conceptual - Not Recommended for New Code)

// 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
    }
}