【VC开源代码栏目提醒】:本文主要为网学会员提供ExamView.cpp,希望对需要ExamView.cpp网友有所帮助,学习一下!
// ExamView.cpp : implementation of the CExamView class
//
#include "stdafx.h"
#include "Exam.h"
#include "ExamDoc.h"
#include "ExamView.h"
#include "NewTeacher.h"
#include "DelTeacher.h"
#include "NewCourse.h"
#include "DelCourse.h"
#include "NewClass.h"
#include "DelClass.h"
#include "NewStudent.h"
#include "DelStudent.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExamView
IMPLEMENT_DYNCREATE(CExamView, CFormView)
BEGIN_MESSAGE_MAP(CExamView, CFormView)
//{{AFX_MSG_MAP(CExamView)
ON_COMMAND(ID_ADD_COURSE, OnAddCourse)
ON_COMMAND(ID_DELETE_COURSE, OnDeleteCourse)
ON_COMMAND(ID_ADD_TEACHER, OnAddTeacher)
ON_COMMAND(ID_DELETE_TEACHER, OnDeleteTeacher)
ON_COMMAND(ID_DELETE_STUDENT, OnDeleteStudent)
ON_COMMAND(ID_ADD_CLASS, OnAddClass)
ON_COMMAND(ID_DELETE_CLASS, OnDeleteClass)
ON_COMMAND(ID_INPUT_MARK, OnInputMark)
ON_COMMAND(ID_SORTBYMARK, OnSortbymark)
ON_COMMAND(ID_QUERY, OnQuery)
ON_COMMAND(ID_COLLECT, OnCollect)
ON_COMMAND(ID_ADD_STUDENT, OnAddStudent)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CExamView construction/destruction
CExamView::CExamView()
: CFormView(CExamView::IDD)
{
//{{AFX_DATA_INIT(CExamView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
m_nCurrPage = 0;
memset( m_arhwndPage, 0, sizeof(HWND)*3 );
}
CExamView::~CExamView()
{
}
void CExamView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExamView)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BOOL CExamView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CExamView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
try
{
// 创建Connection对象
HRESULT hr = m_pConnection.CreateInstance(__uuidof(Connection));
if (SUCCEEDED(hr))
{
// 确定UDL文件路径
CString sConnectionString = "File Name=" + GetExePath() + "\\Datasource.udl";
char temp[100];
::strcpy(temp, sConnectionString);
_bstr_t t(temp);
// 指定UDL文件
m_pConnection->ConnectionString = t;
// 连接数据库
m_pConnection->Open("", "", "", NULL);
}
}
catch (_com_error e)
{
// 显示错误信息
CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s", e.ErrorMessage());
AfxMessageBox(errormessage);
return;
}
// 创建子窗口
CRect rcBaseFrm;
GetClientRect(&rcBaseFrm);
m_Form1.Create(IDD_FORMVIEW_1, this);
m_arhwndPage[0] = m_Form1.GetSafeHwnd();
m_Form2.Create(IDD_FORMVIEW_2, this);
m_arhwndPage[1] = m_Form2.GetSafeHwnd();
m_Form3.Create(IDD_FORMVIEW_3, this);
m_arhwndPage[2] = m_Form3.GetSafeHwnd();
m_Form4.Create(IDD_FORMVIEW_4, this);
m_arhwndPage[3] = m_Form4.GetSafeHwnd();
for (int i = 0; i < 3; i++)
::MoveWindow(m_arhwndPage[i], rcBaseFrm.left + 2, rcBaseFrm.top + 2, rcBaseFrm.Width() - 4, rcBaseFrm.Height() - 4, 0);
::ShowWindow(m_arhwndPage[0], SW_SHOW);
}
/////////////////////////////////////////////////////////////////////////////
// CExamView printing
BOOL CExamView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExamView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExamView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CExamView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CExamView diagnostics
#ifdef _DEBUG
void CExamView::A