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

📄 vc08view.cpp

📁 Visual C++ 6.0编程基础与范例
💻 CPP
字号:
// vc08View.cpp : implementation of the CVc08View class
//

#include "stdafx.h"
#include "vc08.h"

#include "vc08Doc.h"
#include "vc08View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CVc08View

IMPLEMENT_DYNCREATE(CVc08View, CFormView)

BEGIN_MESSAGE_MAP(CVc08View, CFormView)
	//{{AFX_MSG_MAP(CVc08View)
	ON_COMMAND(ID_FirstRec, OnFirstRec)
	ON_UPDATE_COMMAND_UI(ID_FirstRec, OnUpdateFirstRec)
	ON_COMMAND(ID_LastRec, OnLastRec)
	ON_UPDATE_COMMAND_UI(ID_LastRec, OnUpdateLastRec)
	ON_COMMAND(ID_NewRec, OnNewRec)
	ON_COMMAND(ID_NextRec, OnNextRec)
	ON_UPDATE_COMMAND_UI(ID_NextRec, OnUpdateNextRec)
	ON_COMMAND(ID_PrevRec, OnPrevRec)
	ON_UPDATE_COMMAND_UI(ID_PrevRec, OnUpdatePrevRec)
	ON_COMMAND(ID_DelRec, OnDelRec)
	ON_UPDATE_COMMAND_UI(ID_DelRec, OnUpdateDelRec)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CVc08View construction/destruction
CVc08View::CVc08View()
	: CFormView(CVc08View::IDD)
{
	//{{AFX_DATA_INIT(CVc08View)
	m_name = _T("");
	m_price = 0.0f;
	m_index=0;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CVc08View::~CVc08View()
{
}

void CVc08View::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CVc08View)
	DDX_Text(pDX, IDC_EDIT1, m_name);
	DDX_Text(pDX, IDC_EDIT2, m_price);
	DDV_MinMaxFloat(pDX, m_price, 0.f, 9999.f);
	//}}AFX_DATA_MAP
}


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

	return CFormView::PreCreateWindow(cs);
}

void CVc08View::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
//	GetParentFrame()->RecalcLayout();
//	ResizeParentToFit();
	CVc08Doc * pDoc=GetDocument();
	int max=pDoc->GetTotalRec();
	if (max<1)
	{
	m_name=_T("");
	m_price=0;
	pDoc->AddRec(m_name,m_price);
	}
	m_index=0;
	m_name=pDoc->GetRec(0)->m_Name;
	m_price=pDoc->GetRec(0)->m_Price;
	UpdateData(FALSE);
}

/////////////////////////////////////////////////////////////////////////////
// CVc08View printing

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

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CVc08View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CVc08View message handlers

void CVc08View::OnFirstRec() 
{
	// TODO: Add your command handler code here
	UpdateData(TRUE);
	CVc08Doc * pDoc=GetDocument();
	pDoc->SaveRec(m_index,m_name,m_price);
	m_index=0;
	m_name=pDoc->GetRec(m_index)->m_Name;
	m_price=pDoc->GetRec(m_index)->m_Price;
	UpdateData(FALSE);
}

void CVc08View::OnUpdateFirstRec(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_index!=0);	
}

void CVc08View::OnLastRec() 
{
	// TODO: Add your command handler code here
	UpdateData(TRUE);
	CVc08Doc * pDoc=GetDocument();
	pDoc->SaveRec(m_index,m_name,m_price);
	m_index=pDoc->GetTotalRec()-1;
	m_name=pDoc->GetRec(m_index)->m_Name;
	m_price=pDoc->GetRec(m_index)->m_Price;
	UpdateData(FALSE);
}

void CVc08View::OnUpdateLastRec(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CVc08Doc * pDoc=GetDocument();
	int max=pDoc->GetTotalRec();
	pCmdUI->Enable(m_index!=max-1);
}

void CVc08View::OnNewRec() 
{
	// TODO: Add your command handler code here
	UpdateData(TRUE);
	CVc08Doc * pDoc=GetDocument();
	pDoc->SaveRec(m_index,m_name,m_price);
	m_index=pDoc->GetTotalRec();
	m_name=_T("");
	m_price=0;
	UpdateData(FALSE);
	pDoc->AddRec(m_name,m_price);
}

void CVc08View::OnNextRec() 
{
	// TODO: Add your command handler code here
	UpdateData(TRUE);
	CVc08Doc * pDoc=GetDocument();
	pDoc->SaveRec(m_index,m_name,m_price);
	m_index=m_index+1;
	m_name=pDoc->GetRec(m_index)->m_Name;
	m_price=pDoc->GetRec(m_index)->m_Price;
	UpdateData(FALSE);
}

void CVc08View::OnUpdateNextRec(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CVc08Doc * pDoc=GetDocument();
	int max=pDoc->GetTotalRec();
	pCmdUI->Enable(m_index!=max-1);	
}

void CVc08View::OnPrevRec() 
{
	// TODO: Add your command handler code here
	UpdateData(TRUE);
	CVc08Doc * pDoc=GetDocument();
	pDoc->SaveRec(m_index,m_name,m_price);
	m_index=m_index-1;
	m_name=pDoc->GetRec(m_index)->m_Name;
	m_price=pDoc->GetRec(m_index)->m_Price;
	UpdateData(FALSE);
}

void CVc08View::OnUpdatePrevRec(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_index!=0);	
}

void CVc08View::OnDelRec() 
{
	// TODO: Add your command handler code here
	CVc08Doc * pDoc=GetDocument();
	int max=pDoc->GetTotalRec();
	if (max<=1)
	{
		m_name=_T("");
		m_price=0;
		UpdateData(FALSE);
		pDoc->SaveRec(0,m_name,m_price);
		return;
	}
	int index=m_index;
	while (index<max-1)
	{
		m_name=pDoc->GetRec(index+1)->m_Name;
		m_price=pDoc->GetRec(index+1)->m_Price;
		pDoc->SaveRec(index,m_name,m_price);
		index++;
	}
	pDoc->DelRec(index);
	if (index==m_index)
		m_index--;
	m_name=pDoc->GetRec(m_index)->m_Name;
	m_price=pDoc->GetRec(m_index)->m_Price;
	UpdateData(FALSE);
}

void CVc08View::OnUpdateDelRec(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CVc08Doc * pDoc=GetDocument();
	CString name=pDoc->GetRec(m_index)->m_Name;
	int max=pDoc->GetTotalRec();
	pCmdUI->Enable((max!=1) || (name!=_T("")));
}

⌨️ 快捷键说明

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