ex59View.cpp
资源名称:VC6.0.rar [点击查看]
上传用户:qdhmjx
上传日期:2022-07-11
资源大小:2226k
文件大小:3k
源码类别:
书籍源码
开发平台:
Visual C++
- // ex59View.cpp : implementation of the CEx59View class
- //
- #include "stdafx.h"
- #include "ex59.h"
- #include "ex59Doc.h"
- #include "ex59View.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CEx59View
- IMPLEMENT_DYNCREATE(CEx59View, CView)
- BEGIN_MESSAGE_MAP(CEx59View, CView)
- //{{AFX_MSG_MAP(CEx59View)
- ON_WM_RBUTTONDOWN()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CEx59View construction/destruction
- CEx59View::CEx59View()
- {
- // TODO: add construction code here
- }
- CEx59View::~CEx59View()
- {
- }
- BOOL CEx59View::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx59View drawing
- void CEx59View::OnDraw(CDC* pDC)
- {
- CEx59Doc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx59View printing
- BOOL CEx59View::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CEx59View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CEx59View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CEx59View diagnostics
- #ifdef _DEBUG
- void CEx59View::AssertValid() const
- {
- CView::AssertValid();
- }
- void CEx59View::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CEx59Doc* CEx59View::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx59Doc)));
- return (CEx59Doc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CEx59View message handlers
- void CEx59View::OnRButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
- CDC *pDC=GetDC();
- CFont myfont; //定义CFont类
- CFont*oldfont; //定义CFont类的指针
- LOGFONT font; //定义逻辑字体
- memset(&font,0,sizeof(LOGFONT));
- //给font中的所有数据成员赋值为0
- font.lfHeight=-50;//指定字体高度为50
- font.lfWeight=FW_NORMAL;//指定字体粗细
- font. lfCharSet=GB2312_CHARSET;//字符集
- strcpy(font.lfFaceName,"楷体_GB2312");//指定字体
- myfont.CreateFontIndirect(&font); //非直接创建字体
- oldfont=pDC->SelectObject(&myfont);
- TEXTMETRIC tm;//定义TEXTMETRIC结构tm
- pDC->GetTextMetrics(&tm);//获取字体信息
- CString str;
- str.Format("字体的高度为%d",tm.tmHeight);
- //str中存放的内容是"字体的高度-50"
- pDC->TextOut(100,200," 第2种方法创建字体!");
- //用新字体输出字符串
- pDC->SelectObject(oldfont);//恢复设备环境中的旧字体
- pDC->SetTextColor(RGB(255,0,0));
- pDC->TextOut(100,100,str);//输出str字符串
- CView::OnRButtonDown(nFlags, point);
- }