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

📄 newguidedlg.cpp

📁 校园导游系统
💻 CPP
字号:
// newguideDlg.cpp : implementation file
//
//#include <fstream.h>
#include "stdafx.h"
#include "newguide.h"
#include "newguideDlg.h"
//#include "SightInfo1.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:
	int nWidth,nHeight;
	int m_dx,m_dy;
	//{{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()

/////////////////////////////////////////////////////////////////////////////
// CNewguideDlg dialog

CNewguideDlg::CNewguideDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNewguideDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CNewguideDlg)
	m_showout = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CNewguideDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CNewguideDlg)
	DDX_Control(pDX, IDC_COMBOEND, m_cend);
	DDX_Control(pDX, IDC_COMBOBEGIN, m_cbegin);
	DDX_Control(pDX, IDC_SIGHTNAME, m_sightname);
	DDX_Text(pDX, IDC_SHOWOUT, m_showout);
//	DDX_Control(pDX, IDC_BUTTON1, m_Button1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CNewguideDlg, CDialog)
//{{AFX_MSG_MAP(CNewguideDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_QUERY, OnQuery)
ON_BN_CLICKED(IDC_SHOWSIGHTINFO, OnShowsightinfo)
//ON_BN_CLICKED(IDC_BUTTON1, OnCircle)
ON_WM_ERASEBKGND()
	ON_BN_CLICKED(IDC_BUTTON2, OnLeave)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CNewguideDlg message handlers
extern int noEdge=1000;
int **d,**path;	
char info[20][100];
char name[20][30];
int sightflag;
BOOL CNewguideDlg::OnInitDialog()
{
	//pDlg=new CStartUpDlg;
    //pDlg->Create(IDD_STARTUP);//IDD_ID为你的对话框的ID
    //pDlg->ShowWindow(SW_RESTORE);//显示

	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
	
	// TODO: Add extra initialization here
	//char *str;
	//(CStatic*)GetDlgItem(IDC_PPP)->SetBitmap(HBITMAP(Bitmap[0]));
	/*
	CDC *cd;
    cd=(GetDlgItem(IDC_TXT))->GetDC();
    cd->SetTextColor(RGB(11,20,123));
    cd->TextOut(10,10,"fanqingyu");
	*/
	
	CGPushDialogFromCenter(*this); //动态爆炸式推出窗口! 
	ifstream inf("sight.txt");
	if(!inf)
	{
		MessageBox("Wrong Input");
		return false;
	}
	int Sightnum;//景点数
	int road,from,to,w;//边数,两顶点以及两点间的距离
	inf>>Sightnum>>road;
	if(Sightnum<5)
	{
		MessageBox("too little numbers of sights!");
		exit(0);
	}
	Reset(Sightnum,noEdge);
	d=new int *[Sightnum],path=new int *[Sightnum];
	for(int j=0;j<Sightnum;j++)
	{
		d[j]=new int[Sightnum];
		path[j]=new int[Sightnum];
	}
	//CNewguideDlg  graph(int ,int);
	
	
	for(int i=0;i<road;i++)
	{
		inf>>from>>to>>w;
		Add(from,to,w);
	}
	for( j=0;j<Sightnum;j++)
	{
		char *tname;
		tname=new char[Sightnum];
		char tinfo[99];
		inf>>tname>>tinfo;
		strcpy(name[j],tname);
		strcpy(info[j],tinfo);
	}
	//char name[10][20]={"校门","教学楼1","教学楼2","教学楼3","图书馆","南一食堂","南二食堂"};
	//int name[10]={0,1,2,3,4,5,6,7,8,9};
	//char info[10][100]={"南邮的校门很美丽","仙林校区总共有4座教学楼","南邮的图书馆资源丰富,深受同学喜爱"};
	for(i=0;i<Sightnum;i++)
	{
		m_sightname.AddString(name[i]);
	}
	for(i=0;i<Sightnum;i++)
	{
		m_cbegin.AddString(name[i]);
	}
	for(i=0;i<Sightnum;i++)
	{
		m_cend.AddString(name[i]);
	}
	/*
	Add(0,1,10);	
	Add(0,2,40);	
	Add(0,3,40);
	Add(1,2,10);
	Add(2,4,10);
	Add(2,3,10);
	Add(2,5,10);
	Add(3,5,10);
	*/
	//d=new *int[Sightnum],path=new *int[Sightnum];
	TDijkstra(Sightnum,d,path);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

// 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.

CSize GetBitmapSize(const CBitmap&bitmap)
{
	BITMAP stBitmap;
	bitmap.GetObject (sizeof (BITMAP), &stBitmap);
	return CSize(stBitmap.bmWidth, stBitmap.bmHeight);
}

void CNewguideDlg::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
	{
		CDialog::OnPaint();
	}
	///////////////////////
	//获得静态文本框的窗口指针和其设备场景
	/*	CStatic* pTxt = (CStatic*)GetDlgItem(IDC_TXT);
	CDC* pDC = pTxt->GetDC();
	
	  //获得静态文本框的客户区域
	  CRect rc;
	  pTxt->GetClientRect(&rc);
	  
		//创建画背景的画刷,并用其填充背景
		CBrush brush;
		brush.CreateSolidBrush(m_clrBackGround);
		pDC->FillRect(&rc,&brush);
		
		  //设定文字的色彩,并输出文字
		  pDC->SetBkColor(RGB(10,30,100));
		  pDC->SetTextColor(RGB(100,30,10));
		  pDC->DrawText("调色程序",&rc,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
		  pTxt->ReleaseDC(pDC);
	*/
	CDC *cd;
    cd=GetDlgItem(IDC_TXT)->GetDC();
    cd->SetTextColor(RGB(0,0,0));
    cd->TextOut(10,10,"fanqingyu");
	//////////////////////
	/*CRect rectClip,rectTile;
	CDC dcMem,*pDC;
    CBitmap bmBackground;
    bmBackground.LoadBitmap(IDB_BACK); 	//IDB_BG为背景图ID
	
	  //背景尺寸
	  
		CSize sizeBg =GetBitmapSize(bmBackground);	
		pDC = GetDC(); 
		dcMem.CreateCompatibleDC(pDC);
		CBitmap *pbmOld=dcMem.SelectObject(&bmBackground);
		
		  pDC->GetClipBox(&rectClip);    
		  rectTile=CRect(0,0,sizeBg.cx,sizeBg.cy);
		  while (rectTile.top<=rectClip.bottom)
		  {
		  while (rectTile.left<=rectClip.right)
		  {
		  if (!(rectTile & rectClip).IsRectEmpty())				
		  pDC->BitBlt(rectTile.left,rectTile.top, sizeBg.cx,sizeBg.cy,&dcMem,
		  0,0,SRCCOPY);
		  rectTile.left+=sizeBg.cx;
		  rectTile.right+=sizeBg.cx;
		  }
		  rectTile.left=0; rectTile.right=sizeBg.cy;
		  rectTile.top+=sizeBg.cy; rectTile.bottom+=sizeBg.cy;
		  }
		  dcMem.SelectObject(pbmOld);
	dcMem.DeleteDC();*/
}

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

void CNewguideDlg::OnQuery() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	int stack[20]={0},top=0;
	/////////////////
	char selectbegin[15],selectend[15];
	int begin,end;
	m_cbegin.GetWindowText(selectbegin,15);
	begin=m_cbegin.GetCurSel();
	
	m_cend.GetWindowText(selectend,15);
	end=m_cend.GetCurSel();
	////////////////
	
	
	//int begin=m_begin,end=m_end;
	int end1=end;
	char result[50]={""};
	char a[2];
	char flag[6]="---->";
    //end=4;
	strcat(result,"总长度为:");
	itoa(d[begin][end],a,10);
	strcat(result,a);
	strcat(result,"\r\n");
	strcat(result,"路线为:");
	stack[top]=end;	
	while(end>=0)
	{
		if(path[begin][end]>=0)stack[++top]=path[begin][end];		
		end=path[begin][end];
	}
	//MessageBox("the road between ");//<<begin<<" and "<<end1<<" is ";
	while(top>0)
	{
		
		//itoa(stack[top],a,10); 
		strcat(result,name[stack[top]]);
		strcat(result,flag);
		top--;
		
	}
	//itoa(stack[top],a,10);
	strcat(result,name[stack[top]]);
	m_showout=_T(result);
	UpdateData(FALSE);
	/*
	cout<<stack[top];
	cout<<endl;
	
	  cout<<"the shortest length between "<<begin<<" and "<<end<<" is "<<d[begin][end];
	cout<<endl;*/
}

bool CNewguideDlg::Add(int u, int v, const int &w)
{
	if(u<0||v<0||v>n-1||u==v||a[u][v]!=NoEdge)
	{
		//cerr<<"BadInput"<<endl;
		return false;
	}
	a[u][v]=w;
	a[v][u]=w;
	e++;
	return true;
	
}

void CNewguideDlg::Dijkstra(int v, int d[], int path[])
{
	bool *s=new bool[n];
	if(v<0||v>n-1)
	{
		//cerr<<"BadInput"<<endl;
		return;
	}
	for(int i=0;i<n;i++)
	{
		s[i]=false;
		d[i]=a[v][i];
		if(i!=v&&d[i]<NoEdge) path[i]=v;
		else path[i]=-1;
	}
	s[v]=true;d[v]=0;
	for(i=0;i<n-1;i++)
	{
		int u=choose(d,n,s,NoEdge);
		s[u]=true;
		for(int w=0;w<n;w++)
		{
			if(!s[w]&&d[u]+a[u][w]<d[w])
			{
				d[w]=d[u]+a[u][w];
				path[w]=u;
			}//endif
			
		}    //endfor
	}
}

void CNewguideDlg::TDijkstra(int u, int *d[], int *path[])
{
	for(int v=0;v<u;v++)
	{
		Dijkstra(v, d[v], path[v]);
	}
}

//DEL int CNewguideDlg::e()
//DEL {
//DEL 
//DEL }


//DEL CNewguideDlg::CNewguideDlg(int Vertices, int noEdge)
//DEL {
//DEL 	n=Vertices;
//DEL 	NoEdge=noEdge;
//DEL 	a=new int *[n];
//DEL 	for(int i=0;i<n;i++)
//DEL 	{
//DEL 		a[i]=new int [n];
//DEL 		a[i][i]=0;
//DEL 		for(int j=0;j<n;j++)
//DEL 		{
//DEL 			if(i!=j)a[i][j]=NoEdge;
//DEL 		}
//DEL 	}
//DEL }

CNewguideDlg::~CNewguideDlg()
{
	for(int i=0;i<n;i++)
		delete []a[i];
	delete []a;
}

void CNewguideDlg::ShortestLength(int begin, int end, int **d)
{
	
}

void CNewguideDlg::Pathatob(int begin, int end, int **path)
{
	
}

int CNewguideDlg::choose(int d[], int n, bool *s, int MaxNum)
{
	int i,min,minpos;
	min=MaxNum;
	minpos=-1;
	for(i=0;i<n;i++)
	{
		if(d[i]<min&&!s[i])
		{	min=d[i];minpos=i;}
	}
	return minpos;
}

void CNewguideDlg::Reset(int Vertices, int noEdge)
{
	n=Vertices;
	NoEdge=noEdge;
	a=new int *[n];
	for(int i=0;i<n;i++)
	{
		a[i]=new int [n];
		a[i][i]=0;
		for(int j=0;j<n;j++)
		{
			if(i!=j)a[i][j]=NoEdge;
		}
	}
}





void CNewguideDlg::OnShowsightinfo() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	//int name1=m_sightnum;
	//char name[10][20]={"校门","教学楼","图书馆"};
	/*char info[10][100]={"南邮的校门很美丽","教学楼1主要是大一学生的学习场所",
	"教学楼2主要是大二学生的的学习场所","教学楼3主要是大三学生的的学习场所",
	"南邮的图书馆资源丰富,深受同学喜爱","南一食堂有三楼,各有特色",
	"南二食堂有两层,特别深受低年级学生的喜爱",};*/
	char selectname[15];	
	m_sightname.GetWindowText(selectname,15);
	sightflag=m_sightname.GetCurSel();	
	if(sightflag==-1)  //如果用户没有选择景点,给出出错提示
	{
		MessageBox("请选择景点名称!");
		
	}
	else 
		
		//}
	{
		m_sightinfo.CChangeInfo(selectname,info[sightflag]);
		m_sightinfo.DoModal();
	}
	//((CStatic*)m_sightinfo.GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(m_sightinfo.Bitmap[0]));
	//((CStatic*)m_sightinfo.GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(m_sightinfo.Bitmap[i]));
	
	
	/*switch(name1)
	{
	case 0:m_sightinfo.CChangeInfo(name[0],info[0]);break;
	case 1:m_sightinfo.CChangeInfo(name[1],info[1]);break;
	case 2:m_sightinfo.CChangeInfo(name[2],info[2]);break;
	default:break;
}*/
	
	//m_sightinfo.OnInitDialog();
	//m_sightinfo.ShowPic(1);
	
	//m_sightinfo.m_name=name;
	//UpdateData(FALSE);
	
}

//DEL char CNewguideDlg::StringToNum(char sname[])
//DEL {
//DEL 	return 'a';
//DEL }

void CNewguideDlg::OnCircle() 
{
	// TODO: Add your control notification handler code here
	OnOK();
}

BOOL CNewguideDlg::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	BOOL retValue= CDialog::OnEraseBkgnd(pDC);	
	CRect rc;
	GetClientRect(&rc);
	pDC->FillSolidRect(&rc,RGB(205,205,205));	
	return retValue;
	return CDialog::OnEraseBkgnd(pDC);
}

void CNewguideDlg::CGPushDialogFromCenter(CDialog &dlg)
{
	dlg.ShowWindow(SW_HIDE); 
    CRect rect; 
    dlg.GetClientRect(&rect); 
    CPoint ptCenter; 
    ptCenter.x = rect.Width()/2; 
    ptCenter.y = rect.Height()/2; 
    int m = ::GetSystemMetrics(SM_CYSIZEFRAME); 
    //dianamic pop the dlg
    CRgn rgn; 
    for (int i = 10; i < rect.Width()/2 + 2*m; i += 1) 
    { 
        rgn.CreateRectRgn(ptCenter.x - i, ptCenter.y - i, ptCenter.x + i, ptCenter.y + i); 
        dlg.SetWindowRgn((HRGN)rgn, TRUE); 
        dlg.ShowWindow(SW_SHOW); 
        dlg.CenterWindow(); 
        rgn.DeleteObject(); 
    } 

}

void CNewguideDlg::OnLeave() 
{
	// TODO: Add your control notification handler code here
	if ( AfxMessageBox("谢谢您的使用,您确实想退出吗?", MB_OKCANCEL) == IDCANCEL )
      return;// Give the user a chance if he has unknowingly hit the
              // Cancel button. If he says No, return. Don't reset. If
              // Yes, go ahead and reset the values and close the dialog.
    else 
       OnOK();

}

⌨️ 快捷键说明

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