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

📄 ex3_1view.cpp

📁 mfc例题与练习第二版 例题与练习第二版
💻 CPP
字号:
// Ex3_1View.cpp : implementation of the CEx3_1View class
//

#include "stdafx.h"
#include "Ex3_1.h"

#include "Ex3_1Doc.h"
#include "Ex3_1View.h"
#include "StudentDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CEx3_1View

IMPLEMENT_DYNCREATE(CEx3_1View, CView)

BEGIN_MESSAGE_MAP(CEx3_1View, CView)
	//{{AFX_MSG_MAP(CEx3_1View)
	ON_UPDATE_COMMAND_UI(ID_FIRST, OnUpdateFirst)
	ON_COMMAND(ID_FIRST, OnFirst)
	ON_COMMAND(ID_SECOND, OnSecond)
	ON_UPDATE_COMMAND_UI(ID_SECOND, OnUpdateSecond)
	ON_COMMAND(ID_INPUT, OnInput)
	ON_UPDATE_COMMAND_UI(ID_INPUT, OnUpdateInput)
	ON_COMMAND(ID_SHOW, ShowData)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CEx3_1View construction/destruction

CEx3_1View::CEx3_1View()
{
	// TODO: add construction code here
	IsFirst=true;
}

CEx3_1View::~CEx3_1View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEx3_1View drawing

void CEx3_1View::OnDraw(CDC* pDC)
{
	CEx3_1Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
//	pDC->TextOut(0,0,pDoc->m_StrName);
	if(IsFirst)	pDC->TextOut(0,0,pDoc->strFirst);
	else pDC->TextOut(0,0,pDoc->strSecond);

}

/////////////////////////////////////////////////////////////////////////////
// CEx3_1View printing

BOOL CEx3_1View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CEx3_1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CEx3_1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CEx3_1View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CEx3_1View message handlers

void CEx3_1View::OnUpdateFirst(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!IsFirst);	//显示第一个字符串时,禁选"显示first"菜单
}

void CEx3_1View::OnFirst() 
{
	// TODO: Add your command handler code here
	IsFirst=TRUE; 	// 选择"显示first",使IsFirst为TRUE,显示第一个字符串
	Invalidate();  		//使视图无效,实现重画
	
}

void CEx3_1View::OnSecond() 
{
	// TODO: Add your command handler code here
	IsFirst=FALSE;	//选择"显示Second",使IsFirst为FALSE,显示第二个字符串
	Invalidate();

}

void CEx3_1View::OnUpdateSecond(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(IsFirst); 	//显示第二个字符串时,禁选"显示second"菜单项
}

void CEx3_1View::OnInput() 
{
	// TODO: Add your command handler code here
	CEx3_1Doc* pDoc = GetDocument();
	CStudentDlg dlg;						//构造对话框对象
	if(dlg.DoModal()==IDOK) {				//显示对话框并选择OK按钮后
		pDoc->stu.SetStu(dlg);  			//将对话框数据赋给文档数据成员
	}
}

void CEx3_1View::OnUpdateInput(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	
}

void CEx3_1View::ShowData() 
{
	// TODO: Add your command handler code here
	CEx3_1Doc* pDoc = GetDocument();
	CStudentDlg dlg; 						//构造对话框对象

	dlg.Setdata(pDoc->stu);					//将文档数据成员赋给对话框数据成员
	dlg.DoModal();                        //显示对话框,控件显示文档数据

}

⌨️ 快捷键说明

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