• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 375
  • Last Modified:

ActiveX OnDraw Font

Inside my OnDraw function I have code like this

      pdc->SetBkColor(white);
      pdc->FillSolidRect(rcBounds, white);
      pdc->SetTextColor(black);
      pdc->DrawText(m_ticker, -1, rcBounds, DT_SINGLELINE | DT_VCENTER);

I can't find anything to set the Font.  How do I do this?
0
cophi
Asked:
cophi
1 Solution
 
AlexFMCommented:
Create CFont instance and select it in DC using SelectObject:

CFont font;
font.Create(...);

CFont* pOldFont = (CFont*)pdc->SelectObject(&font);

// draw text

pdc->SelectObjectpOldFont nt);
0
 
cophiAuthor Commented:
     CFont *tFont = new CFont();
      tFont->CreateFont(48, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,   DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "Times New Roman");

      CFont* pOldFont = (CFont*)pdc->SelectObject(&tFont);
      pdc->DrawText("hello", -1, r, DT_SINGLELINE | DT_VCENTER);

      pdc->SelectObject(pOldFont);


I just tried this, nothing changed.  Same small font.
0
 
jkrCommented:
You'd better use 'CWnd::SetFont()', e.g.

    CFont *tFont = new CFont();
     tFont->CreateFont(48, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,   DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, "Times New Roman");

    SetFont(tFont);

I'd rather suggest to create the font in your window's constructor.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AlexFMCommented:
CFont* pOldFont = (CFont*)pdc->SelectObject(tFont);
0
 
mahesh1402Commented:
cophi,

In your above code You have pointer to font so you dont need &tFont..just you need SelectObject(tFont)....just changing this will work your above code..

   CFont *tFont = new CFont();
   tFont->CreateFont(48, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, 0, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,   DEFAULT_QUALITY,  
   DEFAULT_PITCH | FF_ROMAN, "Times New Roman");

  //CFont* pOldFont = (CFont*)pdc->SelectObject(&tFont);
  CFont* pOldFont = (CFont*)pdc->SelectObject(tFont); <===========  NOTE it should tFont and not &tFont

  SetFont(tFont);
  pdc->DrawText("hello", -1, r, DT_SINGLELINE | DT_VCENTER);

  pdc->SelectObject(pOldFont);


-MAHESH
0
 
mahesh1402Commented:
oops sorry..

repeat comment .. AlexFM comments were there before I click on submit...

-MAHESH
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now