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

📄 e3_1view.cpp

📁 创建用户界面交互平台,主要是熟悉控件的使用
💻 CPP
字号:
// E3_1View.cpp : implementation of the CE3_1View class
//

#include "stdafx.h"
#include "E3_1.h"

#include "E3_1Doc.h"
#include "E3_1View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CE3_1View

IMPLEMENT_DYNCREATE(CE3_1View, CFormView)

BEGIN_MESSAGE_MAP(CE3_1View, CFormView)
	//{{AFX_MSG_MAP(CE3_1View)
	ON_BN_CLICKED(IDC_ENTER_BUTTON, OnEnterButton)
	ON_BN_CLICKED(IDC_OUTPUT_BUTTON, OnOutputButton)
	ON_BN_CLICKED(IDC_PREV_BUTTON, OnPrevButton)
	ON_BN_CLICKED(IDC_NEXT_BUTTON, OnNextButton)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CE3_1View construction/destruction

CE3_1View::CE3_1View()
	: CFormView(CE3_1View::IDD)
{
	//{{AFX_DATA_INIT(CE3_1View)
	m_Num = 0;
	m_Name = _T("");
	m_Score = 0;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CE3_1View::~CE3_1View()
{
}

void CE3_1View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CE3_1View)
	DDX_Text(pDX, IDC_NUM_EDIT, m_Num);
	DDV_MinMaxInt(pDX, m_Num, 1, 32);
	DDX_Text(pDX, IDC_NAME_EDIT, m_Name);
	DDX_Text(pDX, IDC_SCORE_EDIT, m_Score);
	DDV_MinMaxInt(pDX, m_Score, 0, 100);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CE3_1View::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();
    CE3_1Doc*pDoc=GetDocument();
	m_Index=1;
	m_Num=m_Index;
	m_Name=pDoc->m_Student[m_Index].m_Name;
	m_Score=pDoc->m_Student[m_Index].m_Score;
	UpdateData(FALSE);
}

/////////////////////////////////////////////////////////////////////////////
// CE3_1View printing

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

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

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

void CE3_1View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CE3_1View diagnostics

#ifdef _DEBUG
void CE3_1View::AssertValid() const
{
	CFormView::AssertValid();
}

void CE3_1View::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CE3_1View message handlers

void CE3_1View::OnEnterButton() 
{
	CE3_1Doc*pDoc=GetDocument();                    //获取文档指针
	CEdit*pEdit=(CEdit*)GetDlgItem(IDC_NUM_EDIT);  //获取学号编辑框指针
	CString  temp;
	temp.Format("%d",m_Index);                     //将学号格式化为字符串数据
	pEdit->SetWindowText(temp);                    //将学号按自动升序在Edit1中输出
	if(m_Index<N)
	{
		UpdateData(TRUE);                           //获取文本框数据
		pDoc->m_Student[m_Index].m_Num=m_Num;       //将输入数据存入学生对象数组元素中
        pDoc->m_Student[m_Index].m_Name=m_Name;     //将输入数据存入学生对象数组元素中
		pDoc->m_Student[m_Index].m_Score=m_Score;   //将输入数据存入学生对象数组元素中
		m_Index++;

	}
	else
	{
		MessageBox("输入完毕!","警告!",1);
	}
	// TODO: Add your control notification handler code here
	
}

void CE3_1View::OnOutputButton() 
{
	CE3_1Doc*pDoc=GetDocument();                        //获取文档指针
	CEdit*pEdit=(CEdit*)GetDlgItem(IDC_NAME_EDIT);      //获取姓名编辑框指针
	CString temp;
	pEdit->GetWindowText(temp);
	int flag=0;
	for(int i=1;i<=32;i++)
	{
		if(pDoc->m_Student[i].m_Name==temp)
		{
			m_Num=pDoc->m_Student[i].m_Num;
			m_Name=pDoc->m_Student[i].m_Name;
			m_Score=pDoc->m_Student[i].m_Score;
			UpdateData(FALSE);
			flag=1;
		}
	}
	if(flag==0)
		MessageBox("查无此人!","错误",1);
	// TODO: Add your control notification handler code here
	
}

void CE3_1View::OnPrevButton() 
{
	CE3_1Doc*pDoc=GetDocument();
	if(m_Index>=1&&m_Index<N)
	{
		m_Num=pDoc->m_Student[m_Index].m_Num;
		m_Name=pDoc->m_Student[m_Index].m_Name;
		m_Score=pDoc->m_Student[m_Index].m_Score;
		UpdateData(FALSE);
		m_Index--;
	}
	else
	{
		m_Index=0;
	}
	// TODO: Add your control notification handler code here
	
}


void CE3_1View::OnNextButton() 
{
	CE3_1Doc*pDoc=GetDocument();
	if(m_Index>=1&&m_Index<N)
	{
       m_Num=pDoc->m_Student[m_Index].m_Num;
	   m_Name=pDoc->m_Student[m_Index].m_Name;
	   m_Score=pDoc->m_Student[m_Index].m_Score;
	   UpdateData(FALSE);
	   m_Index++;
	}
	else
	{
		m_Index=0;
	}
	// TODO: Add your control notification handler code here
	
}

void CE3_1View::OnButton1() 
{
    CFile  file;                         //创建文件对象file
	                                     //在E盘创建文件Student.txt
	if(file.Open("E:\\Student.txt",CFile::modeCreate|CFile::modeWrite))
	{
		CE3_1Doc*pDoc=GetDocument();        //获取文档指针pDoc
		CArchive ar(&file,CArchive::store);  //为文件Student.txt创建文件保存缓冲区ar
			for(int i=1;i<=32;i++)
			{
				pDoc->m_Student[i].Serialize(ar);   //为每个对象数组进行序列化操作
				                                    //将对象数据写入文件Student.txt中

			} 
			ar.Close();                            //关闭文件缓冲区

	}
	file.Close();                                  //关闭文件
	// TODO: Add your control notification handler code here
	
}

void CE3_1View::OnButton2() 
{
	CFile file;                         //创建文件对象file
	if(file.Open("E:\\无标题",CFile::modeRead))
	{
		CE3_1Doc*pDoc=GetDocument();           //获取文档指针pDoc
		CArchive ar(&file,CArchive::load);    //将文件数据全部读取到文件缓冲区ar中
		for(int i=1;i<=32;i++)
		{
			pDoc->m_Student[i].Serialize(ar);
			                             //进行序列化操作,将对象数据存放在文挡对象数据中

		}
		ar.Close();                         //关闭文件缓冲区
		 
	}
	file.Close();                        //关闭文件
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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