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

📄 2difsview.cpp

📁 研究现代科学的绝好东西
💻 CPP
字号:
// 2DIFSView.cpp : implementation of the CMy2DIFSView class
//

#include "stdafx.h"
#include "2DIFS.h"

#include "2DIFSDoc.h"
#include "2DIFSView.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "resource.h"
//#include"SetDlg.h"
#define  MaxY  600

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

/////////////////////////////////////////////////////////////////////////////
// CMy2DIFSView

IMPLEMENT_DYNCREATE(CMy2DIFSView, CView)

BEGIN_MESSAGE_MAP(CMy2DIFSView, CView)
	ON_WM_CONTEXTMENU()
	//{{AFX_MSG_MAP(CMy2DIFSView)
	ON_COMMAND(ID_COLOR_MENU, OnColorMenu)
	ON_COMMAND(ID_DRAW_MENU, OnDrawMenu)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMy2DIFSView construction/destruction

CMy2DIFSView::CMy2DIFSView()
{
	// TODO: add construction code here
	m_pColor=RGB(0,255,0);





}

CMy2DIFSView::~CMy2DIFSView()
{
}

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


	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMy2DIFSView drawing

void CMy2DIFSView::OnDraw(CDC* pDC)
{
	CMy2DIFSDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);


	// TODO: add draw code for native data here
 	 m_N=pDoc->m_N;
	 stepx=pDoc->stepx;
	 stepy=pDoc->stepy;
	 totalsteps=pDoc->totalsteps;
	for(int i=0;i<m_N;i++)
	{
		a[i]=pDoc->a[i] ;
		b[i]=pDoc->b[i] ;
		c[i]=pDoc->c[i] ;
		d[i]=pDoc->d[i] ;
		e[i]=pDoc->e[i] ;
		f[i]=pDoc->f[i] ;
	    p[i]=pDoc->p[i] ;
	}  



   


   if(drawtrue==1)
	{
		for(i=1;i<m_N;i++)
		{
			p[i]=p[i]+p[i-1];
		}
				float xj,m;
				x=0;y=0;
				srand(unsigned(time(NULL)));
			for(i=0;i<totalsteps;i++)
			{	 
				m=float(rand());
	
				xj=float(m/RAND_MAX);
				 if(xj<=p[0]) k=0;
				if( (xj>p[0])&&(xj<=p[1])) k=1;
				if( (xj>p[1])&&(xj<=p[2])) k=2;
				if((xj>p[2])&&(xj<=p[3])) k=3;
				if((xj>p[3])&&(xj<=p[4]))k=4;
				if((xj>p[4])&&(xj<=p[5])) k=5;
				if((xj>p[5])&&(xj<=p[6]))k=6;
				if((xj>p[6]) &&(xj<=p[7]))k=7; 

				 
					 
				x=a[k]*x+b[k]*y+e[k];
				y=c[k]*x+d[k]*y+f[k];
				if(i>10)
					pDC->SetPixel(int(MaxY*x/stepx+MaxY/2 ) , MaxY-int(MaxY*y/stepy+30)-100 ,m_pColor);
	
			}
	}


}

/////////////////////////////////////////////////////////////////////////////
// CMy2DIFSView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMy2DIFSView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMy2DIFSView message handlers

void CMy2DIFSView::OnColorMenu() 
{
	// TODO: Add your command handler code here
	CColorDialog colordlg;
	if (colordlg.DoModal()==IDOK)
	{
		m_pColor=colordlg.GetColor();
	}
	Invalidate();

	
}

void CMy2DIFSView::OnDrawMenu() 
{
	// TODO: Add your command handler code here

	drawtrue=1;
	Invalidate();
	
}
 
	
 

void CMy2DIFSView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
 	CMy2DIFSDoc* pDoc =GetDocument();
 	//ASSERT_VALID(pDoc);
 	/* m_N=pDoc->m_N;
		for(  i=0;i<m_N;i++)
	{
		a[i]=pDoc->a[i] ;
		b[i]= pDoc->b[i] ;
		c[i]=pDoc->c[i] ;
		 d[i]=pDoc->d[i] ;
		 e[i]= pDoc->e[i] ;
		 f[i]=pDoc->f[i] ;
		 p[i]=pDoc->p[i] ;
		}  */
}

void CMy2DIFSView::OnContextMenu(CWnd*, CPoint point)
{
	// CG: This block was added by the Pop-up Menu component	{		if (point.x == -1 && point.y == -1){			//keystroke invocation			CRect rect;			GetClientRect(rect);			ClientToScreen(rect);			point = rect.TopLeft();			point.Offset(5, 5);		}		CMenu menu;		VERIFY(menu.LoadMenu(CG_IDR_POPUP_MY2_DIFSVIEW));		CMenu* pPopup = menu.GetSubMenu(0);		ASSERT(pPopup != NULL);		CWnd* pWndPopupOwner = this;		while (pWndPopupOwner->GetStyle() & WS_CHILD)			pWndPopupOwner = pWndPopupOwner->GetParent();		pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,			pWndPopupOwner);	}
}

⌨️ 快捷键说明

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