Click here to Skip to main content
Licence 
First Posted 19 Nov 1999
Views 97,371
Downloads 1,419
Bookmarked 22 times

Automatic Font Handling Class

By Jamie Nordmeyer | 28 Dec 1999
A class to make working with LOGFONTs easier

1

2

3
1 vote, 25.0%
4
3 votes, 75.0%
5
4.27/5 - 19 votes
μ 4.27, σa 0.88 [?]

Sample Image

The CAutoFont class was designed to eliminate the constant, tedious task of filling a LOGFONT structure everytime you need to create or use a font. It was designed to make font manipulation a simple task. Here's a brief example:

void CMyView::OnPaint()
{
    CPaintDC dc(this);
    CAutoFont autofont("Courier New");

    autofont.SetBold(TRUE);
    autofont.SetItalic(TRUE);
    CFont *oldFont=dc.SelectObject(&autofont);
    dc.SetBkMode(TRANSPARENT);
    dc.TextOut(100,100,"Hello World!");
    dc.SelectObject(oldFont);
}

As you can see, CAutoFont works just like a standard CFont object (in fact, it's derived from CFont), except that it has methods built into it for setting its parameters without having to mess with a lengthy LOGFONT structure. Included are two methods for turning the font into a string. This is useful for sending the font to and from the registry, for example. The methods are CAutoFont::ContractFont and CAutoFont::ExtractFont.

Update

CAutoFont now has more functionality built into it. I apologize for forgetting who mentioned it, but per the suggestion of another MFCer, I've added into the ContractFont and ExtractFont functions the ability to save and restore font color. There are also two new functions. GetFontFromDialog allows you to easily incorporate a CFontDialog into your application that automatically updates the CAutoFont class. A CFont object, and a reference to the font's color are also passed back (through pointers) to the caller, if desired. The second function, SetDC, sets a HDC reference for the class to use in calls to GetFontFromDialog, and SetFontColor.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Jamie Nordmeyer

Architect

United States United States

Member

Follow on Twitter Follow on Twitter
I'm a Software Architect, working for a telecom in Portland, OR. My specialties are C#, Win32 C/C++ programming, Visual Basic (6 and .NET), and ASP(.NET), XML/XSL, and database programming. I'm currently learning F#. Completely different than anything I've ever done, but very cool. I'm married to the most wonderful woman, have a beautiful daughter that I'm very proud of, and a step-son that's rocking in high school. I'm also a 2nd degree blackbelt in Olympic style (WTF) Taekwondo, and have trained in Brazilian Jiujitsu, Jeet Kun Do, Krav Maga.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSetFontColor ?? PinmemberChrisRibe9:05 16 Mar '07  
AnswerRe: SetFontColor ?? Pinmemberviaducting2:58 31 Mar '11  
GeneralUpdate is coming, I promise PinmemberJamie Nordmeyer15:52 1 Jan '03  
GeneralRe: Update is coming, I promise Pinmemberhewat6:55 8 Mar '04  
GeneralExtractFont -- HEADS UP! PinmemberTim Gard23:22 28 Sep '02  
GeneralRe: ExtractFont -- HEADS UP! PinmemberJamie Nordmeyer5:52 30 Sep '02  
GeneralAnother solution ... Pinmembercr9722:26 10 Jun '03  
.. is to do at first
 
CString strWork(str);
 
and then use strWork with GetToken() ...
 
cr97
GeneralSmall typo PinsussAnonymous5:15 16 Sep '02  
GeneralPoint Size PinmemberJonny23:23 27 Mar '02  
QuestionPrinting with the selected font? PinmemberMarcus Fries5:29 18 Mar '02  
AnswerRe: Printing with the selected font? PinmemberTerence Russell20:56 30 May '03  
QuestionHow to get Width Pinmemberlaotong16:37 1 Jan '02  
GeneralPoint size PinmemberAnonymous1:38 24 Oct '01  
GeneralGood work!!! PinmemberRejeesh.T.S3:35 1 Aug '01  
GeneralApply Button PinmemberNB0:02 13 Jul '01  
GeneralStill one of my favourite classes PinsussJason Hattingh5:24 7 Aug '00  
GeneralRe: Still one of my favourite classes PinsussJamie Nordmeyer14:52 8 Sep '00  
GeneralExtension for some standard fonts PinmemberThomas Freudenberg1:18 1 Aug '00  
GeneralJamie, your email account seems to do not exist anymore... PinsussThomas Freudenberg1:22 1 Aug '00  
GeneralRe: Jamie, your email account seems to do not exist anymore... PinsussJamie Nordmeyer14:49 8 Sep '00  
GeneralRe: Extension for some standard fonts PinsussJ14:51 8 Sep '00  
GeneralRe: Extension for some standard fonts PinsussJamie Nordmeyer14:51 8 Sep '00  
QuestionResource leak? PinsussSteve Kowald9:14 16 Jun '00  
AnswerRe: Resource leak? PinsussJamie Nordmeyer14:48 8 Sep '00  
AnswerRe: Resource leak? PinmemberRick York9:39 10 Jun '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120210.1 | Last Updated 29 Dec 1999
Article Copyright 1999 by Jamie Nordmeyer
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid