Automatic Font Handling Class | CodeGuru

Automatic Font Handling Class

A while back ago, I realized that I didn’t want to fill in the LOGFONT structure anymore, so I created the CAutoFont class, derived from CFont, so it can be used in place of any CFont objects that you may already have in your code. The benifit of the class is that you don’t have […]

Written By
CodeGuru Staff
CodeGuru Staff
May 1, 2000
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

A while back ago, I realized that I didn’t want to fill in the LOGFONT structure
anymore, so I created the CAutoFont class, derived from CFont, so it can be used
in place of any CFont objects that you may already have in your code. The benifit
of the class is that you don’t have to fill in a LOGFONT structure, or write out a
huge CreateFont command. Simply define a variable of type CAutoFont, with the name
of the font you want as its single parameter (Times New Roman, for example), then
set its parameters as necessary:

CAutoFont font(“Comic Sans MS”);
font.SetBold(TRUE);
font.SetEscapement(900);
font.SetHeight(24);

CAutoFont does all of the LOGFONT and CreateFont work in the background, freeing
the developer from them. Besides font manipulation functions, CAutoFont also has
a function for converting its internal LOGFONT structure into a single string,
which is useful if you want to store the font to the registry, for example, and
a function to convert the string back. In my opinion, very useful.

I’ve included a sample project file with the class. Hope it serves somebody
as well as it’s served me.

Downloads

Download source – 3 Kb
Download demo – 24 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.