📄 testdialogview.cpp
字号:
// TestDialogView.cpp : implementation of the CTestDialogView class
//
#include "stdafx.h"
#include "TestDialog.h"
#include "TestDialogDoc.h"
#include "TestDialogView.h"
#include "TextDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTestDialogView
IMPLEMENT_DYNCREATE(CTestDialogView, CView)
BEGIN_MESSAGE_MAP(CTestDialogView, CView)
//{{AFX_MSG_MAP(CTestDialogView)
ON_COMMAND(ID_TEST_FONTDLG, OnTestFontdlg)
ON_COMMAND(ID_TEST_TEXTDLG, OnTestTextdlg)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CTestDialogView construction/destruction
CTestDialogView::CTestDialogView()
{
m_nX=80;
m_nY=60;
m_strText="珍惜和平!";
m_pCurFont=new CFont;
m_pCurFont->CreateFont(40,0,0,0,
400,FALSE,FALSE,0,
ANSI_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
DEFAULT_PITCH&FF_SWISS,
"Aerial");
m_pDlg=new CTextDlg((CWnd *) this);
}
CTestDialogView::~CTestDialogView()
{
delete m_pCurFont;
delete m_pDlg;
}
BOOL CTestDialogView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTestDialogView drawing
void CTestDialogView::OnDraw(CDC* pDC)
{
CTestDialogDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
Redraw(pDC);
}
/////////////////////////////////////////////////////////////////////////////
// CTestDialogView printing
BOOL CTestDialogView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CTestDialogView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CTestDialogView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CTestDialogView diagnostics
#ifdef _DEBUG
void CTestDialogView::AssertValid() const
{
CView::AssertValid();
}
void CTestDialogView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTestDialogDoc* CTestDialogView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDialogDoc)));
return (CTestDialogDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestDialogView message handlers
void CTestDialogView::Redraw(CDC *pDC)
{
CRect rect;
GetClientRect(&rect);
CBrush* pOldBrush=(CBrush *)pDC->SelectStockObject(WHITE_BRUSH);
pDC->Rectangle(rect);
pDC->SelectObject(pOldBrush);
CFont* pOldFont;
pOldFont=(CFont *)pDC->SelectObject(m_pCurFont);
pDC->SetTextColor(m_nColor);
pDC->TextOut(m_nX,m_nY,m_strText);
pDC->SelectObject(pOldFont);
}
void CTestDialogView::OnTestFontdlg()
{
// TODO: Add your command handler code here
CFontDialog dlg;
int nRet=dlg.DoModal();
if(nRet==IDOK)
{
delete m_pCurFont;
m_pCurFont=new CFont;
m_pCurFont->CreateFont(dlg.GetSize(),
0,0,0,dlg.GetWeight(),
dlg.IsItalic(),
dlg.IsUnderline(),
dlg.IsStrikeOut(),
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH&FF_SWISS,
dlg.GetFaceName());
m_nColor=dlg.GetColor();
}
CDC* pDC=GetDC();
Redraw(pDC);
}
void CTestDialogView::OnTestTextdlg()
{
if(m_pDlg->GetSafeHwnd()==0)
{
//显示对话框
m_pDlg->Create();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -