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

📄 movewnd.cpp

📁 数据结构(C++版)的演示程序
💻 CPP
字号:
// MoveWnd.cpp : implementation file
//

#include "stdafx.h"
#include "BFSearch.h"
#include "MoveWnd.h"
#include <math.h>

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

/////////////////////////////////////////////////////////////////////////////
// CMoveWnd

/////////////////////////////////////////////////////////////////////////////
// CMoveWnd
//设置与窗口相关的静态Control.
CMoveWnd::CMoveWnd(int IDC, CGraph *G)
{
 	 m_IDC=IDC;
	 m_pG = G;
	 m_R_Color=    RGB(255,  0,  0);
	 m_G_Color=    RGB(0,  255,  0);
	 m_B_Color=    RGB(0,  0,  255);
	 m_Bai_Color = RGB(255, 255, 255);
	 m_Hei_Color = RGB(128, 128, 128);
//	 m_ResetWnd = TRUE;
	 m_Blank_Width = 0;
	 m_Blank_Heigh = 0;
	 m_radius = 10;
}

CMoveWnd::~CMoveWnd()
{
}

void CMoveWnd::ChangeDWnd()
{
   double pi = 3.1415926535;
   double a;

	int i, r, ox, oy;
	ox = m_Rect_Width/2;
	oy = m_Rect_Heigh/2;
	if(m_Rect_Width < m_Rect_Heigh)
		r = m_Rect_Width/2 -25;
	else
		r = m_Rect_Heigh/2 -25;
	for(i=0; i<m_pG->n(); i++)
	{
		a = (double)(2*pi*i/m_pG->n());
		m_pG->pos[i].x = ox + (int)(r*cos(a));
		m_pG->pos[i].y = oy + (int)(r*sin(a));
	}
}




BEGIN_MESSAGE_MAP(CMoveWnd, CWnd)
	//{{AFX_MSG_MAP(CMoveWnd)
	ON_WM_PAINT()
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CMoveWnd message handlers

//按相关静态Control设置窗口大小,创立窗口。

BOOL CMoveWnd::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
						DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, 
						UINT nID, CCreateContext* pContext) 
{
	// TODO: Add your specialized code here and/or call the base class
	CWnd       *MoveWnd;

	MoveWnd=pParentWnd->GetDlgItem(m_IDC);
	if(MoveWnd==NULL)throw(0);
	MoveWnd->GetWindowRect(&m_Origin_Rect);
    m_Origin_Rect.DeflateRect(5,5);
	pParentWnd->ScreenToClient(&m_Origin_Rect);
	m_Rect_Width = m_Origin_Rect.Width();
	m_Rect_Heigh = m_Origin_Rect.Height();
	
	return CWnd::Create(lpszClassName, lpszWindowName, dwStyle,
		                m_Origin_Rect, pParentWnd, nID, pContext);
}

void CMoveWnd::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	// TODO: Add your message handler code here
	int i, j;
	char A[2];
	CSize Size;

	A[0] = 'A';
	A[1] = 0;
	if(m_Blank_Width==0)
	{
		Size = dc.GetOutputTextExtent("AAAAAAAAAA");
		m_Blank_Width = Size.cx/10;
		m_Blank_Heigh = Size.cy;
		RPen.CreatePen(PS_SOLID, 2, m_R_Color);
		BackPen.CreatePen(PS_SOLID, 1, m_Hei_Color);
		RBrush.CreateSolidBrush(m_R_Color);
		WBrush.CreateSolidBrush(m_Bai_Color);
		BackBrush.CreateSolidBrush(m_Hei_Color);

	}
	
	dc.SelectObject(&WBrush);
	dc.Rectangle(-1, -1, m_Rect_Width+1, m_Rect_Heigh+1);
	dc.SetTextColor(m_G_Color);
	for(i=0; i<m_pG->n(); i++)
	{
		if(m_pG->getMark(i) == VISITED)
		{
			dc.SetBkColor(m_R_Color);
			dc.SelectObject(&RBrush);
		}
		else
		{
			dc.SetBkColor(m_Hei_Color);
			dc.SelectObject(&BackBrush);
		}
		dc.Ellipse(m_pG->pos[i].x-m_radius, m_pG->pos[i].y-m_radius, m_pG->pos[i].x+m_radius, m_pG->pos[i].y+m_radius);
		dc.TextOut(m_pG->pos[i].x - m_Blank_Width/2, m_pG->pos[i].y-m_Blank_Heigh/2, A);
		A[0]++;
	}


	for(i=0; i<m_pG->n(); i++)
		for(j=i+1; j<m_pG->n(); j++)
		{
			if(m_pG->getEdge(i, j) > 0)
			{
				if(m_pG->getEdge(i, j) <= 1)
					dc.SelectObject(&BackPen);
				else
					dc.SelectObject(&RPen);
				dc.MoveTo(m_pG->pos[i]);
				dc.LineTo(m_pG->pos[j]);
			}
		}
	
	// Do not call CWnd::OnPaint() for painting messages
}

void CMoveWnd::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	int i, rr;
	if((point.x>m_radius)&&(point.y>m_radius)&&(point.x<m_Rect_Width-m_radius)&&(point.x<m_Rect_Heigh-m_radius))
	{
		if(m_Status != 'D')
		{
			for(i=0; i<m_pG->n(); i++)
			{
				rr = (point.x - m_pG->pos[i].x)*(point.x - m_pG->pos[i].x) + (point.y - m_pG->pos[i].y)*(point.y - m_pG->pos[i].y);
				if(rr<=m_radius*m_radius)
					break;
			}
			if(m_Status == 'V')
			{
				if(i>=m_pG->n())
				{
					m_pG->AddVertex(point);
					Invalidate();
				}
			}
			else if(m_Status == 'E')
			{
				if(i<m_pG->n())
				{
					if(m_From == TRUE)
					{
						m_pG->setMark(i, VISITED);
						m_From_V = i;
						m_From = FALSE;
					}
					else
					{
						if(i != m_From_V)
						{
							m_From = TRUE;
							m_pG->setMark(m_From_V, UNVISITED);
							m_pG->SetEdge(m_From_V, i, 1);
							m_pG->SetEdge(i, m_From_V, 1);
						}
					}
					Invalidate();
				}
			}
		}
	}
	CWnd::OnLButtonUp(nFlags, point);
}


/*

/////////////////////////////////////////////////////////////////////////////
// CMoveWnd message handlers
void CMoveWnd::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	int i=0, j, length;
	CString str;
	CSize Size;

	if(m_Blank_Width==0)
	{
		Size = dc.GetOutputTextExtent("          ");
		m_Blank_Width = Size.cx/10;
		m_Blank_Heigh = Size.cy + 1;
		m_Brush = dc.GetCurrentBrush();
	}

	dc.SetBkColor(m_HI_TColor);
	dc.SetTextColor(m_Text_Color);
	for(i=0; i<m_Array_Num; i++)
	{
		str.Format("A[%d]  ", i);
		dc.TextOut(i*54+18, 0, str);
		str.Format("temp[%d]", i);
		dc.TextOut(i*54+8, m_Rect_Heigh-m_Blank_Heigh-1, str);
	}
	dc.SetBkColor(m_Text_Color);
	dc.SetTextColor(m_HI_BColor);
	for(i=0; i<m_Array_Num; i++)
	{
		str.Format("    %2d     ", m_pA[i]);
		dc.TextOut(i*54+5, m_Blank_Heigh, str);
		str.Format("    %02d     ", m_ptemp[i]);
		dc.TextOut(i*54+5, m_Rect_Heigh-2*m_Blank_Heigh-1, str);
	}

	
	if(m_Move_Flag)
	{
		length = m_Blank_Heigh; 
		if(m_FromA_Flag)
		{
			dc.SetBkColor(m_Text_Color);
			dc.SetTextColor(m_HI_BColor);
			str.Format("    %02d     ", m_pA[m_from]);
			dc.TextOut(m_from*54+5, m_Blank_Heigh*2+1, str);
			Sleep(100);
			length = m_Blank_Heigh/2; 
			for(i=m_Blank_Heigh*2+1+length; i<(m_Rect_Heigh-m_Blank_Heigh)/2; i+=length)  
			{
				dc.SetBkColor(m_HI_TColor);
				dc.TextOut(m_from*54+5, i-length, "             ");
				Sleep(100);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(m_from*54+5, i, str);
				Sleep(100);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(m_from*54+5, i-length, "             ");
			Sleep(100);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_from*54+5, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
			Sleep(100);
		}
		else
		{
			dc.SetBkColor(m_Text_Color);
			dc.SetTextColor(m_HI_BColor);
			str.Format("    %02d     ", m_ptemp[m_from]);
			dc.TextOut(m_from*54+5, m_Rect_Heigh-3*m_Blank_Heigh-1, str);
			Sleep(100);
			for(i=m_Rect_Heigh-3*m_Blank_Heigh-1-length; i>(m_Rect_Heigh-m_Blank_Heigh)/2; i-=length)  
			{
				dc.SetBkColor(m_HI_TColor);
				dc.TextOut(m_from*54+5, i+length, "             ");
				Sleep(100);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(m_from*54+5, i, str);
				Sleep(100);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(m_from*54+5, i+length, "             ");
			Sleep(100);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_from*54+5, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
			Sleep(100);
		}

		length = m_Blank_Width*4;
		if(m_from < m_to)
		{
			for(i=m_from*54+5+length; i<m_to*54+5; i+=length)  
			{
				dc.SetBkColor(m_HI_TColor);
				dc.TextOut(i-length, (m_Rect_Heigh-m_Blank_Heigh)/2, "             ");
				Sleep(100);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(i, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
				Sleep(100);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(i-length, (m_Rect_Heigh-m_Blank_Heigh)/2, "             ");
			Sleep(100);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_to*54+5, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
			Sleep(100);
		}
		else
		{
			for(i=m_from*54+5-length; i>m_to*54+5; i-=length)  
			{
				dc.SetBkColor(m_HI_TColor);
				dc.TextOut(i+length, (m_Rect_Heigh-m_Blank_Heigh)/2, "             ");
				Sleep(100);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(i, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
				Sleep(100);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(i+length, (m_Rect_Heigh-m_Blank_Heigh)/2, "             ");
			Sleep(100);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_to*54+5, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
			Sleep(100);
		}
		
		length = m_Blank_Heigh; 
		if(m_ToA_Flag)
		{
			for(i=(m_Rect_Heigh-m_Blank_Heigh)/2-length; i>m_Blank_Heigh+1; i-=length)  
			{
				dc.SetBkColor(m_HI_TColor);
				dc.TextOut(m_to*54+5, i+length, "             ");
				Sleep(100);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(m_to*54+5, i, str);
				Sleep(100);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(m_to*54+5, i+length, "             ");
			Sleep(100);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_to*54+5, m_Blank_Heigh+1, str);
			Sleep(100);
		}
		else
		{
			for(i=(m_Rect_Heigh-m_Blank_Heigh)/2+length; i<m_Rect_Heigh-2*m_Blank_Heigh-1; i+=length)  
			{
				dc.SetBkColor(m_HI_TColor);
				dc.TextOut(m_to*54+5, i-length, "             ");
				Sleep(100);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(m_to*54+5, i, str);
				Sleep(100);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(m_to*54+5, i-length, "             ");
			Sleep(100);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_to*54+5, m_Rect_Heigh-2*m_Blank_Heigh-1, str);
			Sleep(100);
		}
	}
}
*/

⌨️ 快捷键说明

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