FontDlgView.cpp
资源名称:FontDlg.rar [点击查看]
上传用户:taiyu_2006
上传日期:2022-07-26
资源大小:36k
文件大小:3k
源码类别:
对话框与窗口
开发平台:
Visual C++
- // FontDlgView.cpp : implementation of the CFontDlgView class
- //
- #include "stdafx.h"
- #include "FontDlg.h"
- #include "FontDlgDoc.h"
- #include "FontDlgView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFontDlgView
- IMPLEMENT_DYNCREATE(CFontDlgView, CView)
- BEGIN_MESSAGE_MAP(CFontDlgView, CView)
- //{{AFX_MSG_MAP(CFontDlgView)
- ON_COMMAND(ID_VIEW_FONT, OnViewFont)
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CFontDlgView construction/destruction
- CFontDlgView::CFontDlgView()
- {
- // TODO: add construction code here
- }
- CFontDlgView::~CFontDlgView()
- {
- }
- BOOL CFontDlgView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFontDlgView drawing
- void CFontDlgView::OnDraw(CDC* pDC)
- {
- CFontDlgDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- CFont*pfntOld=pDC->SelectObject(&m_fontDlg);
- pDC->SetTextColor(m_clrText);
- pDC->TextOut(10,250,"內容:使用通用字體對話框動態設置字體");
- pDC->SelectObject(pfntOld);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFontDlgView printing
- BOOL CFontDlgView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CFontDlgView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CFontDlgView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFontDlgView diagnostics
- #ifdef _DEBUG
- void CFontDlgView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CFontDlgView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CFontDlgDoc* CFontDlgView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFontDlgDoc)));
- return (CFontDlgDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CFontDlgView message handlers
- void CFontDlgView::OnViewFont()
- {
- // TODO: Add your command handler code here
- CFontDialog dlgFont;
- if(dlgFont.DoModal()==IDOK)
- {
- m_fontDlg.DeleteObject();
- LOGFONT LogFnt;
- dlgFont.GetCurrentFont(&LogFnt);
- m_fontDlg.CreateFontIndirect(&LogFnt);//或m_fontDlg.CreateFontIndirect(dlgFont.m_cf.lpLogFont);
- m_clrText=dlgFont.m_cf.rgbColors;//或m_clrText=dlgFont.GetColor();
- Invalidate();
- }
- }