Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change default used font 1

Status
Not open for further replies.

MvanH

Technical User
May 15, 2001
19
0
0
NL
I want to change the Font that my Ceditview is using to a font that has fixed wides (uhhh the length from left to right, sorry bad english) like Courier new.

When I do this the following way, it doesn't work.
Has anybody got an idee?

--------------------
CFont m_font;
LOGFONT LF;

memset(&lf, 0, sizeof(LOGFONT));
LF.lfHeight = 18;
strcpy(LF.lffacename, "Courier New");
m_font.CreateFontIndirect(&lf);
PEditCtrl.SetFont(&m_font);

----------------------


Martini
 
Steps:

1.CFont m_font; //put it as member of your CEditview class
2.OnInititalUpdate method put

LOGFONT LF;

memset(&lf, 0, sizeof(LOGFONT));
LF.lfHeight = 18;
strcpy(LF.lffacename, "Courier New");
m_font.CreateFontIndirect(&lf);

3.In the OnDraw (or OnPaint) method put this code AFTER the
call to the same method of the base class.

CFont* pOldFont=(CFont*)pDC->SelectObject(&m_font);
//blah, blah code that will write something
pDC->SelectObject(&pOldFont); //restore the old font

(if you dont have a pointer to the DC in the method(pDC) you can get one with the GetDC() method.

Let me know if it works,S-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
THANKS!!!!

I used your OnInitialUpdate methode and it worked.

But can you explain to me Why it worked with the
CFont m_font; as a class member,
In stead of m_font as the function member?

Because that's the only thing that is different in this function............

Thanks a lot!

Martini
 
There are the following thinks different:
1. the m_font is the class member because of some flaws in the MFC Framework and the way Windows works.
I mean:
- graphical objects of an application (fonts, pens, brushes etc) are managed by GDI32.EXE which has a LIMITED MEMORY for this.
- if you create the m_font in the OnDraw method (on the stack or on the heap) for some strange reason the space used by GDI32.EXE won't decrease at the descruction of your GDI Object.

NEVER CONTRUCT GDI OBJECTS IN THE ONDRAW METHOD. You will cause Windows to crush in no time(I know, couse I have done this.) You will get an "YOUR SYSTEM IS LOW ON RESOURCES" system warning. (You can see your system resources with Resource Meter or other application)

2.As you have seen I didn't use the SetFont Method of your control, I prefer the SelectObject method I am familiar with and I know how it works.

Hope this will help others, too

(It took me 2 weeks to find out about this stuff when I had GDI problems)
s-) Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top