// Ex06bView.cpp : implementation of the CEx06bView class // #include "stdafx.h" #include "Ex06b.h" #include "Ex06bDoc.h" #include "Ex06bView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CEx06bView IMPLEMENT_DYNCREATE(CEx06bView, CView) BEGIN_MESSAGE_MAP(CEx06bView, CView) END_MESSAGE_MAP() // CEx06bView construction/destruction CEx06bView::CEx06bView() { // TODO: add construction code here } CEx06bView::~CEx06bView() { } BOOL CEx06bView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } // CEx06bView drawing void CEx06bView::OnDraw(CDC* pDC) { CFont fontTest1, fontTest2, fontTest3, fontTest4; fontTest1.CreateFont(50, 0, 0, 0, 400, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_SWISS, "Arial"); CFont* pOldFont = pDC->SelectObject(&fontTest1); TraceMetrics(pDC); pDC->TextOut(0, 0, "This is Arial, default width"); fontTest2.CreateFont(50, 0, 0, 0, 400, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, "Courier"); // not TrueType pDC->SelectObject(&fontTest2); TraceMetrics(pDC); pDC->TextOut(0, 100, "This is Courier, default width"); fontTest3.CreateFont(50, 10, 0, 0, 400, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_ROMAN, NULL); pDC->SelectObject(&fontTest3); TraceMetrics(pDC); pDC->TextOut(0, 200, "This is generic Roman, variable width"); fontTest4.CreateFont(50, 0, 0, 0, 400, FALSE, FALSE, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN, "LinePrinter"); pDC->SelectObject(&fontTest4); TraceMetrics(pDC); pDC->TextOut(0, 300, "This is LinePrinter, default width"); pDC->SelectObject(pOldFont); } // CEx06bView diagnostics #ifdef _DEBUG void CEx06bView::AssertValid() const { CView::AssertValid(); } void CEx06bView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CEx06bDoc* CEx06bView::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx06bDoc))); return (CEx06bDoc*)m_pDocument; } #endif //_DEBUG // CEx06bView message handlers void CEx06bView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) { CRect clientRect; GetClientRect(clientRect); pDC->SetMapMode(MM_ANISOTROPIC); // +y = down pDC->SetWindowExt(400, 450); pDC->SetViewportExt(clientRect.right, clientRect.bottom); pDC->SetViewportOrg(0, 0); } void CEx06bView::TraceMetrics(CDC* pDC) { TEXTMETRIC tm; char szFaceName[100]; pDC->GetTextMetrics(&tm); pDC->GetTextFace(99, szFaceName); TRACE("font = %s, tmHeight = %d, tmInternalLeading = %d," " tmExternalLeading = %d\n", szFaceName, tm.tmHeight, tm.tmInternalLeading, tm.tmExternalLeading); }