⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex5view.cpp

📁 hen zhongyao de xuexiziliao 稀飯哦
💻 CPP
字号:
// Ex5View.cpp : implementation of the CEx5View class
//

#include "stdafx.h"
#include "Ex5.h"

#include "Ex5Doc.h"
#include "Ex5View.h"

#include "dlglistbox.h"
#include "dlgother.h"
#include "dlgtab.h"
#include "commondlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CEx5View

IMPLEMENT_DYNCREATE(CEx5View, CView)

BEGIN_MESSAGE_MAP(CEx5View, CView)
	//{{AFX_MSG_MAP(CEx5View)
	ON_COMMAND(IDM_ListBox, OnListBox)
	ON_COMMAND(IDM_Other, OnOther)
	ON_COMMAND(IDM_Tab, OnTab)
	ON_COMMAND(IDM_FontDlg, OnFontDlg)
	ON_COMMAND(IDM_FileDialog, OnFileDialog)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEx5View construction/destruction

CEx5View::CEx5View()
{
	// TODO: add construction code here
	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_strFontName="";
	m_nFlags=0;
}

CEx5View::~CEx5View()
{
	delete m_pCurFont;
}

BOOL CEx5View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEx5View drawing

void CEx5View::OnDraw(CDC* pDC)
{
	CEx5Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	reDraw(pDC);

	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CEx5View diagnostics

#ifdef _DEBUG
void CEx5View::AssertValid() const
{
	CView::AssertValid();
}

void CEx5View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CEx5Doc* CEx5View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx5Doc)));
	return (CEx5Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CEx5View message handlers

void CEx5View::OnListBox() 
{
	// TODO: Add your command handler code here
	CDlgListBox dlg1;
	dlg1.DoModal();
}


void CEx5View::OnOther() 
{
	// TODO: Add your command handler code here
	CDlgOther dl1;
	dl1.DoModal();
}

void CEx5View::OnTab() 
{
	// TODO: Add your command handler code here
	CDlgTab dt;
	dt.DoModal();
}

void CEx5View::OnFontDlg() 
{
	// TODO: Add your command handler code here
	m_nFlag=1;

	
	CFontDialog dlg(&m_lf);

	int nRet=dlg.DoModal( );
	if(nRet==IDOK){
		delete m_pCurFont;
		m_pCurFont=new CFont();
		m_pCurFont->CreateFontIndirect(dlg.m_cf.lpLogFont);
		m_lf=*dlg.m_cf.lpLogFont;
		m_nColor=dlg.GetColor( );
		m_strFontName=dlg.GetFaceName();
	}
	CDC* pDC=GetDC( );
	reDraw(pDC);
	
}

void CEx5View::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(40, 40, "我爱MFC编程!");
	if(m_nFlag==1)
	{
		pDC->TextOut(40,180,"字体:"+m_strFontName);

	}
	pDC->SelectObject(pOldFont);
}

void CEx5View::OnFileDialog() 
{
	// TODO: Add your command handler code here
	m_pDlg=new CCommonDlg;
	m_pDlg->Create(CCommonDlg::IDD,this);
	m_pDlg->ShowWindow(SW_SHOW);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -