11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9. Font<br />

);<br />

dc.GetSafeHdc(),<br />

(LPCTSTR)NULL,<br />

(FONTENUMPROC)EnumFontProc,<br />

(LPARAM)m_lpLf<br />

}<br />

m_ptrFont=new CFont[m_nFontCount[0]+m_nFontCount[1]+m_nFontCount[2]];<br />

ptrFont=m_ptrFont;<br />

for(i=0; ilfHeight < 10)(m_lpLf[0]+i)->lfHeight=10;<br />

ptrFont->CreateFontIndirect(m_lpLf[0]+i);<br />

ptrFont++;<br />

sizeTotal.cy+=(m_lpLf[0]+i)->lfHeight;<br />

}<br />

for(i=0; ilfHeight < 10)(m_lpLf[1]+i)->lfHeight=10;<br />

ptrFont->CreateFontIndirect(m_lpLf[1]+i);<br />

ptrFont++;<br />

sizeTotal.cy+=(m_lpLf[1]+i)->lfHeight;<br />

}<br />

for(i=0; ilfHeight < 10)(m_lpLf[2]+i)->lfHeight=10;<br />

ptrFont->CreateFontIndirect(m_lpLf[2]+i);<br />

ptrFont++;<br />

sizeTotal.cy+=(m_lpLf[2]+i)->lfHeight;<br />

}<br />

SetScrollSizes(MM_TEXT, sizeTotal);<br />

After obtaining the information for each type of font, we create a font using this information by calling<br />

function CFont::CreateFontIndirect(…). The addresses of these font objects are stored in array<br />

CGDIView::m_ptrFont.<br />

In function CGDIView::OnDraw(…), the face names of all fonts are output to the client window:<br />

void CGDIView::OnDraw(CDC* pDC)<br />

{<br />

CGDIDoc *pDoc=GetDocument();<br />

ASSERT_VALID(pDoc);<br />

CString szStr;<br />

CFont *ptrFtOld;<br />

CFont *ptrFont;<br />

int nYPos;<br />

int i;<br />

nYPos=10;<br />

szStr.Format("Number of raster fonts: %d", m_nFontCount[0]);<br />

pDC->TextOut(10, nYPos, szStr);<br />

nYPos+=20;<br />

ptrFont=m_ptrFont;<br />

for(i=0; iGetSafeHandle() != NULL);<br />

ptrFtOld=pDC->SelectObject(ptrFont);<br />

pDC->TextOut(10, nYPos, (m_lpLf[0]+i)->lfFaceName);<br />

nYPos+=(m_lpLf[0]+i)->lfHeight;<br />

pDC->SelectObject(ptrFtOld);<br />

ptrFont++;<br />

}<br />

nYPos+=20;<br />

szStr.Format("Number of vector fonts: %d", m_nFontCount[1]);<br />

pDC->TextOut(10, nYPos, szStr);<br />

nYPos+=20;<br />

244

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!