📄 arrayview.cpp
字号:
// ArrayView.cpp : implementation of the CArrayView class
//
#include "stdafx.h"
#include "Array.h"
#include "ArrayDoc.h"
#include "ArrayView.h"
#include "DlgAdd.h"
#include "DlgDelete.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CArrayView
IMPLEMENT_DYNCREATE(CArrayView, CView)
BEGIN_MESSAGE_MAP(CArrayView, CView)
//{{AFX_MSG_MAP(CArrayView)
ON_COMMAND(ID_EDIT_ADD, OnEditAdd)
ON_COMMAND(ID_EDIT_DELETE, OnEditDelete)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CArrayView construction/destruction
CArrayView::CArrayView()
{
// TODO: add construction code here
m_strArray.SetSize(5,5);
m_strArray[0] = "111111111111";
m_strArray[2] = "333333333333";
m_strArray[4] = "555555555555";
}
CArrayView::~CArrayView()
{
}
BOOL CArrayView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CArrayView drawing
void CArrayView::OnDraw(CDC* pDC)
{
CArrayDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// Get the current font's height.
TEXTMETRIC textMetric;
pDC->GetTextMetrics(&textMetric);
int fontHeight = textMetric.tmHeight;
// Get the size of the array.
int count = m_strArray.GetSize();
int displayPos = 10;
// Display the array data.
for (int x=0; x<count; ++x)
{
CString strValue = m_strArray.GetAt(x);
pDC->TextOut(10, displayPos, strValue);
displayPos += fontHeight;
}
}
/////////////////////////////////////////////////////////////////////////////
// CArrayView printing
BOOL CArrayView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CArrayView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CArrayView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CArrayView diagnostics
#ifdef _DEBUG
void CArrayView::AssertValid() const
{
CView::AssertValid();
}
void CArrayView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CArrayDoc* CArrayView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CArrayDoc)));
return (CArrayDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CArrayView message handlers
void CArrayView::OnEditAdd()
{
// TODO: Add your command handler code here
CDlgAdd dlg;
dlg.m_nIndex = 0;
dlg.m_strValue = "Default";
dlg.m_nRadio = 0;
int result = dlg.DoModal();
if (result == IDOK)
{
if (dlg.m_nRadio == 0)
m_strArray.SetAtGrow(dlg.m_nIndex, dlg.m_strValue);
else if (dlg.m_nRadio == 1)
m_strArray.Add(dlg.m_strValue);
else
m_strArray.InsertAt(dlg.m_nIndex, dlg.m_strValue, 1);
Invalidate();
}
}
void CArrayView::OnEditDelete()
{
// TODO: Add your command handler code here
CDlgDelete dlg;
dlg.m_nRadio= 0;
dlg.m_nIndex= 0;
int result = dlg.DoModal();
if (result == IDOK)
{
if (dlg.m_nRadio==0)
m_strArray.RemoveAll();
else
{
if(m_strArray.GetUpperBound() < dlg.m_nIndex)
AfxMessageBox("The index must be less than the array upper bound!");
else
m_strArray.RemoveAt(dlg.m_nIndex);
}
Invalidate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -