?
Solved

I cant get the font correct ?

Posted on 1999-10-29
9
Medium Priority
?
261 Views
Last Modified: 2013-12-03
I have a CWnd drived window that has a
pointer to a CComboBox m_pCBox.
and a CFont* pointer m_pFont.
in construction, I get it as:

CDC* pCBoxpDC = m_pCBox->GetDC();
m_pFont = pCBoxpDC->GetCurrentFont();
m_pCBox->ReleaseDC(pCBoxpDC);

and use it in the windows paint as:

void CNewWnd::OnPaint()
{
CPaintDC dc(this);
dc.SetBkMode(TRANSPARENT);
CRect rc;
GetClientRect(rc);
CFont* pFont = dc.SelectObject(m_pFont);
dc.DrawText(_T("text"), rc, DT_LEFT);
dc.SelectObject(pFont);
}

But text shows bold (darker and ticker
than the combo text)

0
Comment
Question by:has
  • 4
  • 4
9 Comments
 

Author Comment

by:has
ID: 2169861
When I changed the font in ComboBox,
text font is very different.
0
 
LVL 23

Expert Comment

by:chensu
ID: 2169944
The CFont* returned by CDC::GetCurrentFont may be a temporary object, meaning that you can't use it out of scope of a message. Try moving the code into the OnPaint.
0
 

Author Comment

by:has
ID: 2169975
no luck with this

OnPaint()
{
      CDC* pCBoxpDC = m_pCBox->GetDC();

      CPaintDC dc(this); // device context for painting
      dc.SetBkMode(TRANSPARENT);
      CRect rc;
      GetClientRect(rc);
      CFont* pFont = dc.SelectObject(pCBoxpDC->GetCurrentFont());
      dc.DrawText(m_tip, rc, DT_LEFT);
      dc.SelectObject(pFont);

      m_pCBox->ReleaseDC(pCBoxpDC);
      }
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 23

Expert Comment

by:chensu
ID: 2170022
Does CDC::GetCurrentFont return non-NULL? If so, get the font information with CFont::GetLogFont. Then, create your own font object with theLOGFONT structure returned.
0
 

Accepted Solution

by:
liaobin earned 400 total points
ID: 2171023
Hi:
  T think I have got the problem.

CPaintDC dc(this); // device context for painting
dc.SetBkMode(TRANSPARENT);
CRect rc;
GetClientRect(rc);
CFont* pFont = dc.SelectObject(m_pCBox->GetFont());
dc.DrawText(m_tip, rc, DT_LEFT);
dc.SelectObject(pFont);

your couldn't use GetCurrentFont(),
Because MFC Class do something just
like you,it restore original font(system font) after it finished drawing.OK?

0
 
LVL 23

Expert Comment

by:chensu
ID: 2171846
>it restore original font(system font) after it finished drawing.

liaobin is on the right track. I feel that I was stupid.
0
 

Author Comment

by:has
ID: 2174239
Are you telling me that there is a
GetFont() of CDC, or ?? how do I
solve the problem then ??
0
 
LVL 23

Expert Comment

by:chensu
ID: 2174829
GetFont is a member function of CWnd.
0
 

Author Comment

by:has
ID: 2175027
Thanks to both of you.
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question