c语言(或是c++?) 求一个基于MFC的小应用程序

2025-04-17 17:44:26
推荐回答(1个)
回答1:

下面 只是程序,但是mfc是借助界面实现的

#include "stdafx.h"
#include "学生基本信息统计系统.h"

#include "学生基本信息统计系统Set.h"
#include "学生基本信息统计系统Doc.h"
#include "学生基本信息统计系统View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyView

IMPLEMENT_DYNCREATE(CMyView, CRecordView)

BEGIN_MESSAGE_MAP(CMyView, CRecordView)
//{{AFX_MSG_MAP(CMyView)
ON_BN_CLICKED(IDC_BUTTON1next, OnBUTTON1next)
ON_BN_CLICKED(IDC_BUTTON3delete, OnBUTTON3delete)
ON_BN_CLICKED(IDC_BUTTON2add, OnBUTTON2add)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CRecordView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRecordView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction

CMyView::CMyView()
: CRecordView(CMyView::IDD)
{
//{{AFX_DATA_INIT(CMyView)
m_pSet = NULL;
//}}AFX_DATA_INIT
// TODO: add construction code here

}

CMyView::~CMyView()
{
}

void CMyView::DoDataExchange(CDataExchange* pDX)
{
CRecordView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyView)
DDX_FieldText(pDX, IDC_EDIT1name, m_pSet->m_name, m_pSet);
DDX_FieldText(pDX, IDC_EDIT2num, m_pSet->m_num, m_pSet);
DDX_FieldText(pDX, IDC_EDIT3sex, m_pSet->m_sex, m_pSet);
DDX_FieldText(pDX, IDC_EDIT4academy, m_pSet->m_academy, m_pSet);
DDX_FieldText(pDX, IDC_EDIT5score, m_pSet->m_score, m_pSet);
//}}AFX_DATA_MAP
}

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

return CRecordView::PreCreateWindow(cs);
}

void CMyView::OnInitialUpdate()
{
m_pSet = &GetDocument()->m_mySet;
CRecordView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CMyView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics

#ifdef _DEBUG
void CMyView::AssertValid() const
{
CRecordView::AssertValid();
}

void CMyView::Dump(CDumpContext& dc) const
{
CRecordView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CMyView database support
CRecordset* CMyView::OnGetRecordset()
{
return m_pSet;
}

/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers

void CMyView::OnBUTTON1next()
{
// TODO: Add your control notification handler code here
m_pSet->AddNew();
m_pSet->CanUpdate();
m_pSet->Requery();
m_pSet->MoveLast();
UpdateData(FALSE);
}

void CMyView::OnBUTTON3delete()
{
m_pSet->Delete();
m_pSet->MoveNext();
if(m_pSet->IsEOF())
m_pSet->MoveLast();
if(m_pSet->IsBOF())
m_pSet->SetFieldNull(NULL);
UpdateData(FALSE);
}

void CMyView::OnBUTTON2add()
{
// TODO: Add your control notification handler code here

添加代码可以添加学生及其相关信息,仿照其他学生信息!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}