?? bitreeshow001view.cpp
字號:
// BiTreeShow001View.cpp : implementation of the CBiTreeShow001View class
//
#include "stdafx.h"
#include "BiTreeShow001.h"
#include "BiTreeShow001Doc.h"
#include "BiTreeShow001View.h"
#include "BiTree.hpp"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBiTreeShow001View
IMPLEMENT_DYNCREATE(CBiTreeShow001View, CFormView)
BEGIN_MESSAGE_MAP(CBiTreeShow001View, CFormView)
//{{AFX_MSG_MAP(CBiTreeShow001View)
ON_BN_CLICKED(IDC_BUTTON_UP, OnButtonUp)
ON_BN_CLICKED(IDC_BUTTON_MOVELEF, OnButtonMovelef)
ON_BN_CLICKED(IDC_BUTTON_MOVERIGHT, OnButtonMoveright)
ON_BN_CLICKED(IDC_BUTTON__RESET, OnButtonReset)
ON_BN_CLICKED(IDC_BUTTON_INSERTL, OnButtonInsertl)
ON_BN_CLICKED(IDC_BUTTON_INSERTR, OnButtonInsertr)
ON_BN_CLICKED(IDC_BUTTON_CREATEROOT, OnButtonCreateroot)
ON_BN_CLICKED(IDC_BUTTON_SETMAXLAYER, OnButtonSetmaxlayer)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBiTreeShow001View construction/destruction
CBiTreeShow001View::CBiTreeShow001View()
: CFormView(CBiTreeShow001View::IDD)
{
m_LInsertData = 0;
m_RInsertData = 0;
m_MaxLayer = 3;
m_Root = 0;
tmpBitTree.SetMaxLayer(3 - 1);
tmpBitTree.CreateRoot(0);
}
CBiTreeShow001View::~CBiTreeShow001View()
{
}
void CBiTreeShow001View::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBiTreeShow001View)
DDX_Text(pDX, IDC_EDIT_LSDATA, m_LInsertData);
DDX_Text(pDX, IDC_EDIT_RSDATA, m_RInsertData);
DDX_Text(pDX, IDC_EDIT_ROOT, m_Root);
DDX_Text(pDX, IDC_EDIT_MAXLAYER, m_MaxLayer);
//}}AFX_DATA_MAP
}
BOOL CBiTreeShow001View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CBiTreeShow001View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CBiTreeShow001View printing
BOOL CBiTreeShow001View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CBiTreeShow001View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CBiTreeShow001View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CBiTreeShow001View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CBiTreeShow001View diagnostics
#ifdef _DEBUG
void CBiTreeShow001View::AssertValid() const
{
CFormView::AssertValid();
}
void CBiTreeShow001View::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CBiTreeShow001Doc* CBiTreeShow001View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBiTreeShow001Doc)));
return (CBiTreeShow001Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBiTreeShow001View message handlers
void CBiTreeShow001View::OnDraw(CDC* pDC)
{
CSinList<int>* tmpCoorList = tmpBitTree.GetCoorList();
CSinList<int>* tmpSubLabel = tmpBitTree.GetNodeLabelList();
CSinList<int>* tmpConList = tmpBitTree.GetNodeConList();
tmpCoorList->RemoveAll();
tmpSubLabel->RemoveAll();
tmpConList->RemoveAll();
tmpBitTree.PreOlderTree(tmpBitTree.GetRootNode(), 0, 0, 0);
tmpBitTree.FillCoorRegion();
//////////////////////////////////////////////////////////////////////////
// Draw Line
CRect tmpRect;
COOR tmpCurCoor = tmpBitTree.GetCurrentCoor();
tmpRect.left = tmpCurCoor.XCoor + 8;
tmpRect.right = tmpCurCoor.XCoor + 30;
tmpRect.top = tmpCurCoor.YCoor + 8;
tmpRect.bottom = tmpCurCoor.YCoor + 30;
CBrush* tmpBrush = new CBrush(RGB(255, 0, 0));
CBrush* pOldBrush = NULL;
pDC->Rectangle(&tmpRect);
pDC->SelectObject(&pOldBrush);
for(int nCirTmp = 1; nCirTmp < tmpSubLabel->GetCount(); nCirTmp += 2)
{
int nStartSubLabel = nCirTmp;
int nSrcData = tmpSubLabel->GetAt(nCirTmp);
int nFindData = nSrcData * 2;
int nEndSubLabel = tmpSubLabel->Find(nFindData, 1, 2);
if(nEndSubLabel != -1)
{
pDC->MoveTo(tmpCoorList->GetAt(nCirTmp - 1) + 19, tmpCoorList->GetAt(nCirTmp) + 19) ;
pDC->LineTo(tmpCoorList->GetAt(nEndSubLabel - 1) + 19,
tmpCoorList->GetAt(nEndSubLabel) + 19);
}
int nSndFindData = nSrcData * 2 + 1;
nEndSubLabel = tmpSubLabel->Find(nSndFindData, 1, 2);
if(nEndSubLabel != -1)
{
pDC->MoveTo(tmpCoorList->GetAt(nCirTmp - 1) + 19, tmpCoorList->GetAt(nCirTmp) + 19);
pDC->LineTo(tmpCoorList->GetAt(nEndSubLabel - 1) + 19,
tmpCoorList->GetAt(nEndSubLabel) + 19);
}
}
//////////////////////////////////////////////////////////////////////////
// Draw Circle
for(nCirTmp = 0; nCirTmp < tmpCoorList->GetCount(); nCirTmp += 2)
{
int xTmp = tmpCoorList->GetAt(nCirTmp);
int yTmp = tmpCoorList->GetAt(nCirTmp + 1);
tmpRect.left = xTmp + 8;
tmpRect.right = xTmp + 30;
tmpRect.top = yTmp + 8;
tmpRect.bottom = yTmp + 30;
pDC->Ellipse(&tmpRect);
CString tmpStr;
tmpStr.Format("%d", tmpConList->GetAt(nCirTmp / 2));
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(tmpStr, &tmpRect, DT_CENTER);
}
}
void CBiTreeShow001View::OnButtonUp()
{
tmpBitTree.Parent();
Invalidate(TRUE);
}
void CBiTreeShow001View::OnButtonMovelef()
{
// TODO: Add your control notification handler code here
tmpBitTree.LChild();
Invalidate(TRUE);
}
void CBiTreeShow001View::OnButtonMoveright()
{
tmpBitTree.RChild();
Invalidate(TRUE);
}
void CBiTreeShow001View::OnButtonReset()
{
tmpBitTree.Root();
Invalidate(TRUE);
}
void CBiTreeShow001View::OnButtonInsertl()
{
UpdateData(TRUE);
int nTmp = m_LInsertData;
tmpBitTree.InsertLChild(nTmp);
Invalidate(TRUE);
}
void CBiTreeShow001View::OnButtonInsertr()
{
UpdateData(TRUE);
int nTmp = m_RInsertData;
tmpBitTree.InsertRChild(nTmp);
Invalidate(TRUE);
}
void CBiTreeShow001View::OnButtonCreateroot()
{
UpdateData(TRUE);
int nTmpData = m_Root;
tmpBitTree.CreateRoot(nTmpData);
Invalidate(TRUE);
}
void CBiTreeShow001View::OnButtonSetmaxlayer()
{
UpdateData(TRUE);
int nTmpData = m_MaxLayer - 1;
tmpBitTree.SetMaxLayer(nTmpData);
Invalidate(TRUE);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -