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

📄 fxsview.cpp

📁 关于分形L系统的应用
💻 CPP
字号:
// fxsView.cpp : implementation of the CFxsView class
//

#include "stdafx.h"
#include "fxs.h"

#include "fxsDoc.h"
#include "fxsView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFxsView

IMPLEMENT_DYNCREATE(CFxsView, CScrollView)

BEGIN_MESSAGE_MAP(CFxsView, CScrollView)
	//{{AFX_MSG_MAP(CFxsView)
	ON_WM_PAINT()
	ON_COMMAND(IDM_SET, OnSet)
	ON_WM_LBUTTONDOWN()
	ON_WM_RBUTTONDOWN()
	ON_WM_MOUSEWHEEL()
	ON_WM_ERASEBKGND()
	ON_WM_CANCELMODE()
	//}}AFX_MSG_MAP
	// 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()

/////////////////////////////////////////////////////////////////////////////
// CFxsView construction/destruction

CFxsView::CFxsView()
{
	// TODO: add construction code here

}

CFxsView::~CFxsView()
{
}

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

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CFxsView drawing

void CFxsView::OnDraw(CDC* pDC)
{
	CFxsDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CFxsView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CFxsView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CFxsView message handlers
void CFxsView::OnPaint() 
{
	AfxGetMainWnd()->SetWindowText("分形树");

	
	CPaintDC dc(this); // device context for painting
	


	CRect rect;
	GetClientRect(&rect);

	//*************************
	//MemDC用于双缓冲
	CDC MemDC;										// 定义一个内存DC(双缓存)
	MemDC.CreateCompatibleDC(NULL);                 // 建立与屏幕显示兼容的DC
//	CFont *oldfont=MemDC.SelectObject(&font);
//	CPen *oldpen=MemDC.SelectObject(&pen[4]);
	// 建立一个与屏幕显示兼容的位图
	CBitmap MemBitmap;                              // 定义一个位图对象
	MemBitmap.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
	MemDC.SelectObject(&MemBitmap);					// 将位图选入DC
	// 用背景色将位图填充
	MemDC.FillSolidRect(0, 0, rect.Width(), rect.Height(),RGB(200, 200, 240));
	MemDC.SetBkMode(TRANSPARENT);
	dc.SetBkMode(TRANSPARENT);
	/*******************************
	
    
	// 设置所要求背景色的刷子
	CBrush backBrush(RGB(200, 200, 240));
	// 保存旧刷子
	CBrush* pOldBrush = dc.SelectObject(&backBrush);
	//CRect rect;
	//dc.GetClipBox(&rect);     // 擦除所需的区域
	dc.PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
	dc.SelectObject(pOldBrush);

	***********************************/
	//双缓冲后续步骤
	////////////////////////////////////////////////////////////////////////
	// 然后将内存中的图拷贝到屏幕上进行显示
	dc.BitBlt(0, 0, rect.Width(), rect.Height(), &MemDC, 0, 0, SRCCOPY);
	// 绘图完成后MemDC的释放
	MemBitmap.DeleteObject();
 	MemDC.DeleteDC();
	//还原字体和画笔
	//MemDC.SelectObject(oldfont);
	//MemDC.SelectObject(oldpen);
	/*******************************************/

	dc.TextOut(0,0,"左键放大,右键缩小,中键滑鼠控制上下移动");

	CPen pen( PS_SOLID , 1 , RGB(10,120,10) );
	CPen *oldpen = dc.SelectObject(&pen);

	
	int px=rect.Width()/2;//初始化主干起点
	int py=rect.Height();
	tree.Draw(&dc,px,py);

	dc.SelectObject(oldpen);
	
	// Do not call CFrameWnd::OnPaint() for painting messages
}


void CFxsView::OnSet() 
{
	// TODO: Add your command handler code here

	tree.Set();

}


void CFxsView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	tree.ZoneOut();
	this->Invalidate();
	CScrollView::OnLButtonDown(nFlags, point);
}



void CFxsView::OnRButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default


	tree.ZoneIn();
	this->Invalidate();
	CScrollView::OnRButtonDown(nFlags, point);
}

BOOL CFxsView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	// TODO: Add your message handler code here and/or call default
	if(zDelta>0)
		tree.Up();
	else
		tree.Down();
		this->Invalidate();
	return CScrollView::OnMouseWheel(nFlags, zDelta, pt);
}

  






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

void CFxsView::OnCancelMode() 
{
	CScrollView::OnCancelMode();
	
	// TODO: Add your message handler code here

}

⌨️ 快捷键说明

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