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

📄 ex702view.cpp

📁 在视图里实现链表
💻 CPP
字号:
// Ex702View.cpp : implementation of the CEx702View class
//

#include "stdafx.h"
#include "MyHeader.h"


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

/////////////////////////////////////////////////////////////////////////////
// CEx702View

IMPLEMENT_DYNCREATE(CEx702View, CScrollView)

BEGIN_MESSAGE_MAP(CEx702View, CScrollView)
	//{{AFX_MSG_MAP(CEx702View)
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	ON_COMMAND(ID_LISTOP_DEL, OnListOpDel)
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONUP()
	//}}AFX_MSG_MAP
	ON_MESSAGE(MSG_UPDATE,OnDataUpdate)
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEx702View construction/destruction

CEx702View::CEx702View()
{
	// TODO: add construction code here
	m_pDlg=new CInputDlg;
	m_pDlg->SetParent(this);
	m_bMoving=FALSE;
}

CEx702View::~CEx702View()
{
	delete m_pDlg;
}

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

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CEx702View drawing

void CEx702View::OnDraw(CDC* pDC)
{
	CEx702Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	pDoc->m_pList->Draw(pDC);
}

void CEx702View::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal(10000,10000);
	CSize sizePage(sizeTotal.cx/4,sizeTotal.cy/4);
	CSize sizeLine(sizePage.cx/40,sizePage.cy/40);
	// TODO: calculate the total size of this view
	SetScrollSizes(MM_LOMETRIC,sizeTotal,sizePage,sizeLine);
}

/////////////////////////////////////////////////////////////////////////////
// CEx702View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CEx702View diagnostics

#ifdef _DEBUG
void CEx702View::AssertValid() const
{
	CScrollView::AssertValid();
}

void CEx702View::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CEx702View message handlers

void CEx702View::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CInputDlg aDlg;
	if(aDlg.DoModal()==IDOK)
	{
		CNode* pNode=new CNode;
		pNode->SetData(aDlg.m_LVal,aDlg.m_RVal);
		CClientDC dc(this);
		
		OnPrepareDC(&dc);
		dc.DPtoLP(&point);
		pNode->SetPos(point.x,point.y);
		
		CEx702Doc* pDoc=GetDocument();
		ASSERT_VALID(pDoc);
		pDoc->m_pList->Add(pNode);
		Invalidate();
	}
}

void CEx702View::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
/*	if(m_pDlg->GetSafeHwnd()==NULL)
		m_pDlg->Create(CInputDlg::IDD);
	m_pDlg->ShowWindow(SW_SHOWNORMAL);
	*/

	CClientDC dc(this);
	OnPrepareDC(&dc);

	CEx702Doc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);

	if(pDoc->m_pList->SetCurrent(&dc,point))
	{
		m_bMoving=TRUE;
		SetCapture();
		m_ptPrev=point;
	}
}

void CEx702View::OnDataUpdate()
{
	m_pDlg->UpdateData(TRUE);
	AfxMessageBox(m_pDlg->m_strInfo,MB_OK,0);

}

void CEx702View::OnListOpDel() 
{
	// TODO: Add your command handler code here
	CEx702Doc* pDoc=GetDocument();
	ASSERT_VALID(pDoc);
	pDoc->m_pList->DeleteNode();
	Invalidate();
}

void CEx702View::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_bMoving)
	{
		int xOff=point.x-m_ptPrev.x;
		int yOff=point.y-m_ptPrev.y;
		
		CEx702Doc* pDoc=GetDocument();
		ASSERT_VALID(pDoc);
		CClientDC dc(this);
		OnPrepareDC(&dc);
		CPoint pt(xOff,yOff);

		dc.DPtoLP(&pt);
		pDoc->m_pList->Offset(pt.x,pt.y);
		m_ptPrev=point;
		Invalidate();
	}
}

void CEx702View::OnRButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_bMoving)
	{
		m_bMoving=FALSE;
		ReleaseCapture();
	}
}

⌨️ 快捷键说明

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