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

📄 mywnd.cpp

📁 红黑树——一种数据结构的可视化画法
💻 CPP
字号:
// MyWnd.cpp : implementation file
//

#include "stdafx.h"
#include "红黑树.h"
#include "MyWnd.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyWnd
void  drawNode(pNode pn,int px,int py,int wg,CDC* pDC);
void drawRBtree(pNode pn,int px,int py,int wx,CDC*pDC);
extern rbTree gtree;
IMPLEMENT_DYNCREATE(CMyWnd, CMDIChildWnd)

CMyWnd::CMyWnd()
{
	this->SetScrollRange(SB_HORZ ,0,150);
	this->SetScrollRange(SB_VERT ,-100,100);
}

CMyWnd::~CMyWnd()
{
}


BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
	//{{AFX_MSG_MAP(CMyWnd)
	ON_WM_CLOSE()
	ON_WM_CANCELMODE()
	ON_WM_PAINT()
	ON_WM_CAPTURECHANGED()
	ON_COMMAND(ID_APP_EXIT, OnAppExit)
	ON_WM_VSCROLL()
	ON_WM_CHAR()
	ON_WM_CONTEXTMENU()
	ON_WM_MOUSEWHEEL()
	ON_WM_COPYDATA()
	ON_WM_LBUTTONDBLCLK()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyWnd message handlers

void CMyWnd::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	
	CWnd::OnClose();
}

void CMyWnd::OnCancelMode() 
{
	CWnd::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

void CMyWnd::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	drawTree();

}

void CMyWnd::OnCaptureChanged(CWnd *pWnd) 
{
	// TODO: Add your message handler code here
	
	CWnd::OnCaptureChanged(pWnd);
}

void CMyWnd::OnAppExit() 
{
	// TODO: Add your command handler code here
	this->DestroyWindow();
	
}

void CMyWnd::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
	CDC* pDC=this->GetDC();
	CString str;
	str.Format("nSBCode=%d,nPos=%d",nSBCode,nPos);
	pDC->TextOut(0,0,str);
	 this->SetScrollPos(SB_VERT,nPos);
	//CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CMyWnd::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default

	this->DestroyWindow();

	
	
}

void CMyWnd::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code here
	
}

BOOL CMyWnd::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	// TODO: Add your message handler code here and/or call default
//	int nPos=this->GetScrollPos(SB_VERT);
//		 this->SetScrollPos(SB_VERT,nPos-zDelta/30);
	return CWnd::OnMouseWheel(nFlags, zDelta, pt);
}

BOOL CMyWnd::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) 
{
	// TODO: Add your message handler code here and/or call default
	
	return CWnd::OnCopyData(pWnd, pCopyDataStruct);
}

void CMyWnd::drawTree()
{
	CDC*pdc=this->GetDC();

	int height=gtree.Bheight(gtree.root);
	height=height*2-1;
	int wx=1<<height;
	if(wx<9)
	wx=60*wx;
	else if(wx<15)
		wx=30*wx;
	else if(wx<20)
		wx=24*wx;
	else if(wx<33)
		wx=16*wx;
	else if(wx<50)
		wx=12*wx;
	else if(wx<129)
		wx=7*wx;
	else
    wx=4*wx;

   drawRBtree(gtree.root,480-wx,-60,wx,pdc);
	
}

//void CMyWnd::drawNode(pNode node, CPoint ppos, int wg)
//{

//}

void CMyWnd::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	this->DestroyWindow();
	
//CWnd::OnLButtonDblClk(nFlags, point);
}

⌨️ 快捷键说明

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