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

📄 showview.cpp

📁 数据结构中的图最短路径问题
💻 CPP
字号:
// ShowView.cpp : implementation of the CShowView class
//

#include "stdafx.h"
#include "图最短路径.h"

#include "ShowDoc.h"
#include "ShowView.h"
#include "NodeDialog.h"
#include "DialogStart.h"
#include ".\showview.h"

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

/////////////////////////////////////////////////////////////////////////////
// CShowView

IMPLEMENT_DYNCREATE(CShowView, CView)

BEGIN_MESSAGE_MAP(CShowView, CView)
	//{{AFX_MSG_MAP(CShowView)
	ON_COMMAND(ID_FIND, OnFind)
	ON_UPDATE_COMMAND_UI(ID_FIND, OnUpdateFind)
	ON_WM_TIMER()
	ON_WM_PAINT()
	ON_COMMAND(ID_SET, OnSet)
	ON_UPDATE_COMMAND_UI(ID_SET, OnUpdateSet)
	ON_WM_VSCROLL()
	ON_WM_HSCROLL()
	ON_WM_ERASEBKGND()
	//}}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)
	ON_COMMAND(ID_START, OnStart)
	ON_UPDATE_COMMAND_UI(ID_START, OnUpdateStart)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowView construction/destruction

CShowView::CShowView()
{
	// TODO: add construction code here
	m_bStarFind=false;
	m_nStar=0;
	m_Char = 'A';

}

CShowView::~CShowView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CShowView drawing

void CShowView::OnDraw(CDC* pDC)
{
	CShowDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CRect rect;
	CString  string;
	string.AppendChar(m_Char);
	if(!m_bStarFind)
		pDC->TextOut(150,10,"寻找"+string+"点到个点的最短路径");
	else
		pDC->TextOut(200,10,"正在寻找......");
	rect=CRect(50,60,450,460);
	pDoc->m_cPicture.Show(pDC,&rect);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CShowView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CShowView diagnostics

#ifdef _DEBUG
void CShowView::AssertValid() const
{
	CView::AssertValid();
}

void CShowView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CShowView message handlers

void CShowView::OnFind() 
{
	// TODO: Add your command handler code here
	CShowDoc* pDoc = GetDocument();
	SetTimer(1,2000,NULL);
	m_bStarFind=true;
	pDoc->m_cPicture.Perform(m_Char-'A');
	Invalidate();
}

void CShowView::OnUpdateFind(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_bStarFind)
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
	
}

void CShowView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CShowDoc* pDoc = GetDocument();
	if(!pDoc->m_cPicture.Perform())
	{
		m_bStarFind=false;
		KillTimer(1);
	}
	Invalidate();
	CView::OnTimer(nIDEvent);
}


void CShowView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	CRect rect;//(160,10,180,30);
	SCROLLINFO scroll;
	GetClientRect(&rect);
	GetScrollInfo(SB_HORZ,&scroll);
	scroll.cbSize = rect.Width();
	scroll.nMax= 1000;
	scroll.nMin=0;
	scroll.nPage=rect.Width();
	scroll.nPos=0;
	SetScrollInfo(SB_HORZ,&scroll);
	if(scroll.nMax>scroll.nPage)
		EnableScrollBarCtrl(SB_HORZ, true);
	else
		EnableScrollBarCtrl(SB_HORZ, false);

	GetScrollInfo(SB_VERT,&scroll);
	scroll.cbSize = rect.Height();
	scroll.nMax=800;
	scroll.nMin=0;
	scroll.nPage=rect.Height();
	scroll.nPos=0;
	SetScrollInfo(SB_VERT,&scroll);
	if(scroll.nMax>scroll.nPage)
		EnableScrollBarCtrl(SB_VERT, true);
	else
		EnableScrollBarCtrl(SB_VERT, false);
}

void CShowView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	//OnDraw(&dc);

	OnPrepareDC(&dc);
	OnDraw(&dc);
	
	// Do not call CView::OnPaint() for painting messages
}

void CShowView::OnSet() 
{
	// TODO: Add your command handler code here
	CShowDoc* pDoc = GetDocument();
	CNodeDialog dialog;
	dialog.m_nNodeSize=pDoc->m_nSize;
	if(dialog.DoModal()==IDOK)
	{
		pDoc->m_nSize=dialog.m_nNodeSize;
		pDoc->m_cPicture.Destroy();
		pDoc->m_cPicture.Create(pDoc->m_nSize);
		pDoc->m_cPicture.Random();
		Invalidate();
	}
}

void CShowView::OnUpdateSet(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_bStarFind)
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
	
}

void CShowView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	if(pScrollBar != NULL && pScrollBar->SendChildNotifyLastMsg())
		return ;
	if(pScrollBar != GetScrollBarCtrl(SB_VERT))
		return ;
	SCROLLINFO scroll;
	GetScrollInfo(SB_VERT,&scroll);
	switch(nSBCode)
	{
	case SB_TOP:
		scroll.nPos=0;
		break;
	case SB_BOTTOM:
		scroll.nPos=scroll.nMax-scroll.nPage;
		break;
	case SB_LINEUP:
		scroll.nPos=scroll.nPos-10;
		break;
	case SB_LINEDOWN:
		scroll.nPos=scroll.nPos+10;
		break;
	case SB_PAGEUP:
		scroll.nPos=scroll.nPos-scroll.nPage;
		break;
	case SB_PAGEDOWN:
		scroll.nPos=scroll.nPos+scroll.nPage;
		break;
	case SB_THUMBTRACK:
		scroll.nPos = nPos;
		break;
	default :
		break;
	}

	SetScrollInfo(SB_VERT,&scroll);
	Invalidate(true);
	
	CView::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CShowView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	if(pScrollBar != NULL && pScrollBar->SendChildNotifyLastMsg())
		return ;
	if(pScrollBar != GetScrollBarCtrl(SB_HORZ))
		return ;
	SCROLLINFO scroll;
	GetScrollInfo(SB_HORZ,&scroll);
    switch(nSBCode)
	{
	case SB_LEFT:
		scroll.nPos=0;
		break;
	case SB_RIGHT:
		scroll.nPos=scroll.nMax-scroll.nPage;
		break;
	case SB_LINELEFT:
		scroll.nPos=scroll.nPos-10;
		break;
	case SB_LINERIGHT:
		scroll.nPos=scroll.nPos+10;
		break;
	case SB_PAGELEFT:
		scroll.nPos=scroll.nPos-scroll.nPage;
		break;
	case SB_PAGERIGHT:
		scroll.nPos=scroll.nPos+scroll.nPage;
		break;
	case SB_THUMBTRACK:
		scroll.nPos = nPos;
		break;
	default :
		break;
	}
	SetScrollInfo(SB_HORZ,&scroll);
	Invalidate(true);
	
	CView::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CShowView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
{
	// TODO: Add your specialized code here and/or call the base class
	CRect rect;
	SCROLLINFO scroll;
	GetClientRect(&rect);
	GetScrollInfo(SB_HORZ,&scroll);
	scroll.cbSize = rect.Width();
	scroll.nMax= 1000;
	scroll.nMin=0;
	scroll.nPage=rect.Width();
	SetScrollInfo(SB_HORZ,&scroll);
	if(scroll.nMax>scroll.nPage)
		EnableScrollBarCtrl(SB_HORZ, true);
	else
		EnableScrollBarCtrl(SB_HORZ, false);

	GetScrollInfo(SB_VERT,&scroll);
	scroll.cbSize = rect.Height();
	scroll.nMax=800;
	scroll.nMin=0;
	scroll.nPage=rect.Height();
	SetScrollInfo(SB_VERT,&scroll);
	if(scroll.nMax>scroll.nPage)
		EnableScrollBarCtrl(SB_VERT, true);
	else
		EnableScrollBarCtrl(SB_VERT, false);

	CPoint cPOrg(GetScrollPos(SB_HORZ), GetScrollPos(SB_VERT));
	pDC->SetViewportOrg(-cPOrg);
	//m_cEdit.SetWindowPos(NULL,160-cPOrg.x,10-cPOrg.y,20,20,NULL);
	CView::OnPrepareDC(pDC, pInfo);
}

BOOL CShowView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	
	return CView::OnEraseBkgnd(pDC);
}

void CShowView::OnStart()
{
	// TODO: 在此添加命令处理程序代码
	CShowDoc* pDoc = GetDocument();
	CDialogStart dialog;
	dialog.m_nSize = pDoc->m_nSize;
	if(dialog.DoModal() != IDOK)
		return ;
	m_Char = dialog.m_nChar;
	Invalidate(true);
}

void CShowView::OnUpdateStart(CCmdUI *pCmdUI)
{
	// TODO: 在此添加命令更新用户界面处理程序代码
	if(m_bStarFind)
		pCmdUI->Enable(false);
	else
		pCmdUI->Enable(true);
}

⌨️ 快捷键说明

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