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

📄 maxstreamview.cpp

📁 学习VC的时候写的
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MaxStreamView.cpp : implementation of the CMaxStreamView class
//

#include <math.h>
#include <string.h>
#include "stdafx.h"
#include "MaxStream.h"

#include "MaxStreamDoc.h"
#include "MaxStreamView.h"
#include "DlgDrawLine.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMaxStreamView

IMPLEMENT_DYNCREATE(CMaxStreamView, CView)

BEGIN_MESSAGE_MAP(CMaxStreamView, CView)
	//{{AFX_MSG_MAP(CMaxStreamView)
	ON_COMMAND(ID_INPUTPOINT, OnInputpoint)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_COMMAND(ID_LINE, OnLine)
	ON_COMMAND(ID_Compute, OnCompute)
	ON_COMMAND(ID_SetZero, OnSetZero)
	ON_COMMAND(ID_INPUTHELP, OnInputhelp)
	ON_COMMAND(ID_FILE_SAVE, OnFileSave)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	//}}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_MESSAGE(WM_DIALOG,OnDialog)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMaxStreamView construction/destruction

CMaxStreamView::CMaxStreamView()
{
	// TODO: add construction code here	 
    m_hCross=AfxGetApp()->LoadStandardCursor(IDC_CROSS);
	OperationChoice=0;
	PointNumber=0;
	dlg=NULL;
	NN=0;
	m_nTheMaxStream=0;
	int i,j;
	for(i=0;i<25;i++)
	  for(j=0;j<25;j++)
	  {
	    m_nMax[i][j]=0;
		m_nActual[i][j]=0;
		m_nMin[i][j]=0;
	  }
}

CMaxStreamView::~CMaxStreamView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMaxStreamView drawing

void CMaxStreamView::OnDraw(CDC* pDC)
{
	CMaxStreamDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	if(OperationChoice==0)
	{
	
	}
	if(OperationChoice==1)
	{
	   int i=PointNumber-1;	 
	   while(i>=0)	
	   {
	     CString strText;
		 strText.Format("V%d",i+1);
         pDC->Ellipse(m_ptResource[i].x-3,m_ptResource[i].y-3,m_ptResource[i].x+3,m_ptResource[i].y+3);
	     pDC->TextOut(m_ptResource[i].x-3,m_ptResource[i].y+7,strText);
	     i--;
	   }
	}
	if(OperationChoice==2)
	{
	   int i=PointNumber-1;	 
	   while(i>=0)	
	   {
	     CString strText;
		 strText.Format("V%d",i+1);
         pDC->Ellipse(m_ptResource[i].x-3,m_ptResource[i].y-3,m_ptResource[i].x+3,m_ptResource[i].y+3);
	     pDC->TextOut(m_ptResource[i].x-3,m_ptResource[i].y+7,strText);
	     i--;
	   }
	   int j,k;
       for(j=0;j<25;j++)
	   {
	     for(k=0;k<25;k++)
            if(m_nMax[j][k]!=0)
			{
			  CString TempText1,TempText2;
			  TempText1.Format("%d",m_nMax[j][k]);
			  TempText2.Format("\(%d\)",m_nActual[j][k]);
			  ArrowLine(m_ptResource[j],m_ptResource[k]);
			  Label(m_ptResource[j],m_ptResource[k],TempText1,TempText2);
			}  
	   }
	}
	if(OperationChoice==3)
	{
	 int i=PointNumber-1;	 
	   while(i>=0)	
	   {
	     CString strText;
		 strText.Format("V%d",i+1);
         pDC->Ellipse(m_ptResource[i].x-3,m_ptResource[i].y-3,m_ptResource[i].x+3,m_ptResource[i].y+3);
	     pDC->TextOut(m_ptResource[i].x-3,m_ptResource[i].y+7,strText);
	     i--;
	   }
	   int j,k;
       for(j=0;j<25;j++)
	   {
	     for(k=0;k<25;k++)
            if(m_nMax[j][k]!=0)
			{
			  CString TempText1,TempText2;
			  TempText1.Format("%d",m_nMax[j][k]);
			  TempText2.Format("\(%d\)",m_nActual[j][k]);
			  ArrowLine(m_ptResource[j],m_ptResource[k]);
			  Label(m_ptResource[j],m_ptResource[k],TempText1,TempText2);
			}  
	   }
    //////////////////////////////////////////////////////////////////////
     CString TextOutput;
	 TextOutput.Format("最大流是:%d",m_nTheMaxStream);
	 pDC->TextOut(10,10,TextOutput);
	 CPen PenNew;
	 PenNew.CreatePen(PS_DASH,1,RGB(0,0,255));
	 CPen *pPenOld;
     pPenOld=pDC->SelectObject(&PenNew);
	 int nn;	
	 for(nn=1;nn<NN;nn++)
	 {
		pDC->MoveTo(c_pMidMin[nn-1]);
		pDC->LineTo(c_pMidMin[nn]);
	 }
	 pDC->SelectObject(pPenOld);
	 PenNew.DeleteObject();
	}
}

/////////////////////////////////////////////////////////////////////////////
// CMaxStreamView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMaxStreamView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMaxStreamView message handlers

void CMaxStreamView::OnInputpoint() 
{
	// TODO: Add your command handler code here
	OperationChoice=1;
	PointNumber=0;
}

void CMaxStreamView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(OperationChoice!=1)
		return;
	SetCapture();
	::SetCursor(m_hCross);
	m_ptTemp=point;
	if(PointNumber<25)
	   m_ptResource[PointNumber++]=m_ptTemp;
	else
	   MessageBox("节点数超过25!","错误",MB_ICONWARNING|MB_OK);
	CView::OnLButtonDown(nFlags, point);
}

BOOL CMaxStreamView::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	return CView::DestroyWindow();
}

void CMaxStreamView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	//Invalidate();
	if(OperationChoice!=1)
	{   
		ReleaseCapture();
		return;
	}
	CString strText;
	int i;
	i=PointNumber;
	strText.Format("V%d",i);
	CClientDC dc(this);
	dc.Ellipse(m_ptTemp.x-3,m_ptTemp.y-3,m_ptTemp.x+3,m_ptTemp.y+3);
	dc.TextOut(m_ptTemp.x-3,m_ptTemp.y+7,strText);
	ReleaseCapture();
	CView::OnLButtonUp(nFlags, point);
}

void CMaxStreamView::OnLine() 
{
	// TODO: Add your command handler code here
	OperationChoice=2;
	if(dlg==NULL)
	{
	dlg=new DlgDrawLine;
	dlg->Create(IDD_LINE,NULL);
	dlg->ShowWindow(SW_SHOW);
	}
	else
		dlg->SetActiveWindow();
}
LRESULT CMaxStreamView::OnDialog(WPARAM wParam,LPARAM lParam)
{
  switch(wParam)
  {
  case IDOK:
	  m_nMax[dlg->m_nStart-1][dlg->m_nEnd-1]=dlg->m_nMax;
	  m_nActual[dlg->m_nStart-1][dlg->m_nEnd-1]=dlg->m_nActual;
	  dlg->DestroyWindow();
	  delete dlg;
	  dlg=NULL;
	  break;
  case IDCANCEL:
	  dlg->DestroyWindow();
	  delete dlg;
	  dlg=NULL;
	  break;
  case IDNEXT:
	  m_nMax[dlg->m_nStart-1][dlg->m_nEnd-1]=dlg->m_nMax;
	  m_nActual[dlg->m_nStart-1][dlg->m_nEnd-1]=dlg->m_nActual;
	  break;
  }
  Invalidate();
  return 0;
}

void CMaxStreamView::ArrowLine(CPoint c_pStart,CPoint c_pEnd)
{
  CClientDC dc(this);
  dc.MoveTo(c_pStart);
  dc.LineTo(c_pEnd);
  float m_fTan;
  m_fTan=(float)(c_pStart.y-c_pEnd.y)/(c_pStart.x-c_pEnd.x);
  float m_fCos,m_fSin;
  m_fCos=(float)(1/sqrt(1+m_fTan*m_fTan));
  m_fSin=(float)sqrt(m_fTan*m_fTan/(1+m_fTan*m_fTan));
  CPoint ArrowMid,ArrowFirst,ArrowSecond;
///////////////////////////////////////////////////////////////////
  if(c_pEnd.x>=c_pStart.x&&c_pEnd.y>c_pStart.y)
  {
  ArrowMid.x=(int)(c_pEnd.x-10*m_fCos+0.5);
  ArrowMid.y=(int)(c_pEnd.y-10*m_fSin+0.5);
  ArrowFirst.x=(int)(ArrowMid.x-2*m_fSin+0.5);
  ArrowFirst.y=(int)(ArrowMid.y+2*m_fCos+0.5);
  ArrowSecond.x=(int)(ArrowMid.x+2*m_fSin+0.5);
  ArrowSecond.y=(int)(ArrowMid.y-2*m_fCos+0.5);
  }
  if(c_pEnd.x>=c_pStart.x&&c_pEnd.y<c_pStart.y)
  {

⌨️ 快捷键说明

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