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

📄 索引技术dlg.cpp

📁 是当初的数据结构的做业,用的是b+树这一块,非常值得初学者的参考
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 索引技术Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "索引技术.h"
#include "索引技术Dlg.h"
#include "speedDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
	m_num = 0;
	m_time=5000;
	m_insert=-1;
	m_stop=false;
	traval=false;
	insertval=-1;
	insertplace=0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_state=-1;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
bool CMyDlg::PrintTree(CPaintDC & dc,CRect rect[],Node noderect[],FTNode *subroot,int num)
{  CBrush *old;CBrush b;
b.CreateSolidBrush(RGB(12,13,255));
	if(subroot==NULL || subroot->lkey==EMPTY ||num >20) return true;

FTNode *node[5]={NULL,NULL,NULL,NULL,NULL};
dc.Rectangle(&rect[num]);
if(m_insert==subroot->lkey)
{old=dc.SelectObject(&b);
dc.Rectangle(&rect[num]);
dc.SelectObject(old);
}
int number=2;
CString s;
s.Format("%d",subroot->lkey);
dc.TextOut(rect[num].left,rect[num].CenterPoint().y,s);
if(subroot->ckey!=EMPTY)
{if(m_insert==subroot->ckey) old=dc.SelectObject(&b);

CRect temp=CRect(rect[num].left+(rect[num].right-rect[num].left),rect[num].top,rect[num].right+(rect[num].right-rect[num].left),rect[num].bottom);
dc.Rectangle(temp);
s.Format("%d",subroot->ckey);
dc.TextOut(temp.left,temp.CenterPoint().y,s);number=3;
if(m_insert==subroot->ckey) dc.SelectObject(old);
}
if(subroot->rkey!=EMPTY){
if(m_insert==subroot->rkey) old=dc.SelectObject(&b);
CRect temp=CRect(rect[num].left+2*(rect[num].right-rect[num].left),rect[num].top,rect[num].right+2*(rect[num].right-rect[num].left),rect[num].bottom);
	  dc.Rectangle(temp);
s.Format("%d",subroot->rkey);

dc.TextOut(temp.left,temp.CenterPoint().y,s);number=4;if(m_insert==subroot->rkey)  dc.SelectObject(old);}
node[0]=NULL;
node[1]=subroot->left;
node[2]=subroot->lcenter;
node[3]=subroot->rcenter;
node[4]=subroot->right;


CPoint p[5];
p[0]=CPoint(0,0);
p[1]=noderect[num].lpoint;
p[2]=noderect[num].clpoint;
p[3]=noderect[num].rlpoint;
p[4]=noderect[num].rpoint;
for(int i=1;i<=number;i++)

{   if(node[i]!=NULL)
{
	dc.MoveTo(p[i]);
    dc.LineTo(noderect[4*num+i].toppoint);
}
	PrintTree(dc,rect,noderect,node[i],4*num+i);
}

return true;
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Control(pDX, IDC_EDIT1, m_edit);
	DDX_Control(pDX, IDC_BUTTON8, m_btn8);
	DDX_Control(pDX, IDC_BUTTON7, m_btn7);
	DDX_Control(pDX, IDC_BUTTON6, m_btn6);
	DDX_Control(pDX, IDC_BUTTON5, m_btn5);
	DDX_Control(pDX, IDC_BUTTON4, m_btn4);
	DDX_Control(pDX, IDC_BUTTON3, m_btn3);
	DDX_Control(pDX, IDC_BUTTON2, m_btn2);
	DDX_Control(pDX, IDC_BUTTON1, m_btn1);
	DDX_Control(pDX, IDC_3D, m_3D);
	DDX_Control(pDX, IDC_3D2, m_3D2);
	DDX_Control(pDX,IDC_STATIC3,m_3D3);
	DDX_Text(pDX, IDC_EDIT1, m_num);
	DDV_MinMaxInt(pDX, m_num, 1, 99);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON7, Oninsert)
	ON_BN_CLICKED(IDC_BUTTON8, Onfind)
	ON_BN_CLICKED(IDC_BUTTON1, Onrun)
	ON_BN_CLICKED(IDC_BUTTON3, OnSpeedCtrl)
	ON_BN_CLICKED(IDC_BUTTON5, OnRadom)
	ON_BN_CLICKED(IDC_BUTTON2, OnStop)
	ON_BN_CLICKED(IDC_BUTTON4, OnTraval)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::OnInitDialog()
{   //CRect m_rect1;
    //CRect m_rect2;
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	//m_btn1.SetBitmap(
	// TODO: Add extra initialization here
	ShowWindow(SW_SHOWMAXIMIZED);

		//AfxMessageBox("******************");
	//list->GetClientRect(&m_rect2);
	m_3D.SetFont3D(TRUE,CLabel::Raised)
		.SetText3DHiliteColor(RGB(0,0,255))
		.SetFontName("Times New Roman")
		.SetFontSize(16)
		.SetFontBold(TRUE);
	m_3D2.SetFont3D(TRUE,CLabel::Raised)
		.SetText3DHiliteColor(RGB(0,255,50))
		.SetFontName("Times New Roman")
		.SetFontSize(32)
		.SetFontBold(TRUE);
	m_3D3.SetFont3D(TRUE,CLabel::Raised)
		.SetText3DHiliteColor(RGB(255,0,0))
		.SetFontName("楷 书")
		.SetFontSize(35)
		.SetFontBold(TRUE);
	CFont font;
	font.CreateFont(-15,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_MODERN,"Courier New");
 
	SetTimer(1,500,NULL);
	GetClientRect(&rect);
	//CStatic *cs=(CStatic *)GetDlgItem(IDC_STATIC5);
	//cs->GetClientRect(&m_rect1);
    rect.top=115;
	rect.bottom=rect.bottom-228;
	//设置演示区域大小
    int rctWidth=(rect.Width())/61;
    int rctHeight=rect.Height()/3;

	for(int i=0;i<180;i++)
		
	{  int b=i%60;int a=(i-b)/60;
	
		rct[i]=CRect(rect.left+b * rctWidth,rect.top+a*rctHeight+95-40,rect.left+b*rctWidth+rctWidth,rect.top+a*rctHeight+rctHeight-40);
    }
	int a=0;int b=0;
	noderct[0]=rct[30];
	for(a=1;a<=4;a++)
	{
		noderct[a]=rct[(60*a)/5+60];
		

	}
	int k=0;
	for(a=5,k=0;a<=21;a++)
	{noderct[a]=rct[k*4+120];

	k++;
	}

   for(int y=0;y<3;y++)
   {validate[y]=CRect(rct[y*60].left,rct[y*60].top,rct[y*60].right,rct[y*60].bottom);
   }
    noderct[20]=CRect(noderct[19].left+60,noderct[19].top,noderct[19].right+60,noderct[19].bottom);
	for(int c=0;c<=20;c++)
	{node[c].toppoint.x=noderct[c].right;
	node[c].toppoint.y=noderct[c].top;
	node[c].lpoint=CPoint(noderct[c].left,noderct[c].bottom);
	node[c].clpoint=CPoint(noderct[c].right,noderct[c].bottom);
    node[c].rlpoint=CPoint(noderct[c].left+2*(noderct[c].right-noderct[c].left),noderct[c].bottom);
    node[c].rpoint=CPoint(noderct[c].left+3*(noderct[c].right-noderct[c].left),noderct[c].bottom);
	}
	CFont font1;
	font1.CreateFont(-15,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_MODERN,"Courier New");
    CListBox *list1=(CListBox *)GetDlgItem(IDC_LIST1);
    PathName+="code.txt";
    CString ss;
	CStdioFile f((LPSTR)(LPCTSTR)PathName,CFile::modeRead);
	f.SeekToBegin();
	f.ReadString(ss);
	int t=0;
	while(ss!=_T(""))
	{
    list1->InsertString(t++,ss);
	ss.Empty();
    f.ReadString(ss);
	}
    list1->SetFont(&font);
	//list1->
	list1->SetCurSel(0);
	m_edit.SetFont(&font1);
	//m_edit.set
	FTNode *rt=new FTNode;
    tree.root=rt;
	for(int o=0;o<21;o++)
	{
		insertrect[o]=CRect(noderct[o].left,2*noderct[o].top-noderct[o].bottom,noderct[o].right,noderct[o].top);
	}
  for(o=0;o<21;o++)
	{
		splitenoderect[o]=CRect(noderct[o].left+3*(noderct[o].right-noderct[o].left),noderct[o].top,noderct[o].left+4*(noderct[o].right-noderct[o].left),noderct[o].bottom);
		m_retval[o]=-1;
	}
	 return TRUE;  // return TRUE  unless you set the focus to a cont rol
}

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

void CMyDlg::OnDestroy()
{
	WinHelp(0L, HELP_QUIT);
	KillTimer(1);
	CDialog::OnDestroy();
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMyDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
	 CPaintDC dc(this);
	 dc.SetBkMode(0);
	 //dc.FillSolidRect(&rect,RGB(200,0,255)); //User for test;
	 dc.TextOut(rect.CenterPoint().x-20,rect.CenterPoint().y-5,"B-树课件");
	 //Print();
	 
	 PrintTree(dc,noderct,node,tree.root,0);//打印b树
	// if(traval==true)
	 //Traval(dc,noderct,node,tree.root,0,m_insert);
	 //traval=false;
	 
	if(insertval!=-1 &&insertval<=99 && insertval!=-1&&insertplace<=20 && insertplace>=0)//有数据插入时
	 {
      CString s;
	  s.Format("%d",insertval);
	  dc.FillSolidRect(&insertrect[insertplace],RGB(255,0,0));
	  dc.TextOut(insertrect[insertplace].left,insertrect[insertplace].CenterPoint().y,s);
	 }
	for(int i=0;i<=20;i++)
	{   if(m_retval[i]!=-1)
	{   CString s;
	    s.Format("%d",m_retval[i]);
	
		dc.FillSolidRect(&splitenoderect[i],RGB(0,255,0));
		dc.TextOut(splitenoderect[i].left,splitenoderect[i].CenterPoint().y,s);
	}
	}
	 CDialog::OnPaint();
	}
	
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMyDlg::OnButton6() 
{
	// TODO: Add your control notification handler code here
	exit(0);
}

void CMyDlg::OnTimer(UINT nIDEvent) //无效函数,仅用于调试
{
	// TODO: Add your message handler code here and/or call default
	//CSize off;
	//off.cx=10;
	//off.cy=20;
	//InvalidateRect(&rect,TRUE);
    //rect=rect+off;
	static int a=0;
	CDialog::OnTimer(nIDEvent);
	//InvalidateRect(&rect,TRUE);
	//CListBox *list=(CListBox *)GetDlgItem(IDC_LIST1);
	//list->SetCurSel(a%6);
	//a++;

}

void CMyDlg::Oninsert() 
{  
	const int i=GetDlgItemInt(IDC_EDIT1);
	
    if(i<=0 || i>99)
	{MessageBox("请先输入0~~~~100的数据!!");
	
	return;
	}
   m_state=0;
   state="插入状态";

   SetDlgItemText(IDC_STATIC3,state);
	m_3D3.SetFont3D(TRUE,CLabel::Raised)
		.SetText3DHiliteColor(RGB(255,0,0))
		.SetFontName("Times New Roman")
		.SetFontSize(35)
		.SetFontBold(TRUE);
	CListBox *list1=(CListBox *)GetDlgItem(IDC_LIST1);
    while(list1->GetCount())
		list1->DeleteString(0);
    char path[50];
	GetModuleFileName(NULL,path,50);
    int len=strlen(path);
    PathName=path;
	char q='\'';
	int l=PathName.ReverseFind(q);
    len=l;
	path[l+1]=0;
    PathName=path;
	l=PathName.ReverseFind(q);
    path[l+1]=0;
    PathName=path;
    PathName.Insert(PathName.GetLength(),"code.txt");
	CString ss;
	CStdioFile f((LPSTR)(LPCTSTR)PathName,CFile::modeRead);
	f.SeekToBegin();
	f.ReadString(ss);
	int t=0;
	while(ss!=_T(""))
	{
    list1->InsertString(t++,ss);
	ss.Empty();
    f.ReadString(ss);
	}
	m_btn7.EnableWindow(FALSE);
	m_btn8.EnableWindow(FALSE);
    m_edit.EnableWindow(FALSE);
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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