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

📄 movewnd.cpp

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

#include "stdafx.h"
#include "MoveWnd.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMoveWnd
//设置与窗口相关的静态Control.
CMoveWnd::CMoveWnd(int IDC)
{
 	 m_IDC=IDC;
	 
	 m_BK_Color  = RGB(192, 192, 192);
	 m_HI_BColor = RGB(255,   0,   0);
	 m_Text_Color= RGB(  0, 128,   0);
	 m_HI_TColor = RGB(255, 255, 255);
	 m_ResetWnd = TRUE;
	 m_pA = NULL;
	 m_ptemp = NULL;
 	 m_Blank_Width = 0;
	 m_Blank_Heigh = 0;
}

//按相关静态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  *TextReg;
    CRect      Origin_Rect;

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

void CMoveWnd::SetMoveWnd(int *A, int *temp, int Array_Num)
{
	int i;
	if(m_pA)
		delete m_pA;
	if(m_ptemp)
		delete m_ptemp;
	m_pA = new int[Array_Num];
	m_ptemp = new int[Array_Num];
	m_Array_Num = Array_Num;
	for(i=0; i<m_Array_Num; i++)
	{
		m_pA[i] = A[i];
		m_ptemp[i] = temp[i];
	}
	m_Move_Flag = FALSE;
}

CMoveWnd::~CMoveWnd()
{
	if(m_pA)
		delete m_pA;
	if(m_ptemp)
		delete m_ptemp;
	m_Blank_String.Empty();
}


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


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

	val = 50;
	if(m_Blank_Width==0)
	{
		Size = dc.GetOutputTextExtent("          ");
		m_Blank_Width = Size.cx/10;
		m_Blank_Heigh = Size.cy;
		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)
	{
		if(((m_from - m_to)>2)||((m_from - m_to)<-2))
			val = 40;
		if(((m_from - m_to)>4)||((m_from - m_to)<-4))
			val = 30;
		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(val);
			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(val);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(m_from*54+5, i, str);
				Sleep(val);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(m_from*54+5, i-length, "             ");
			Sleep(val);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_from*54+5, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
			Sleep(val);
		}
		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(val);
			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(val);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(m_from*54+5, i, str);
				Sleep(val);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(m_from*54+5, i+length, "             ");
			Sleep(val);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_from*54+5, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
			Sleep(val);
		}

		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(val);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(i, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
				Sleep(val);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(i-length, (m_Rect_Heigh-m_Blank_Heigh)/2, "             ");
			Sleep(val);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_to*54+5, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
			Sleep(val);
		}
		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(val);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(i, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
				Sleep(val);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(i+length, (m_Rect_Heigh-m_Blank_Heigh)/2, "             ");
			Sleep(val);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_to*54+5, (m_Rect_Heigh-m_Blank_Heigh)/2, str);
			Sleep(val);
		}
		
		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(val);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(m_to*54+5, i, str);
				Sleep(val);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(m_to*54+5, i+length, "             ");
			Sleep(val);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_to*54+5, m_Blank_Heigh+1, str);
			Sleep(val);
		}
		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(val);
				dc.SetBkColor(m_Text_Color);
				dc.TextOut(m_to*54+5, i, str);
				Sleep(val);
			}
			dc.SetBkColor(m_HI_TColor);
			dc.TextOut(m_to*54+5, i-length, "             ");
			Sleep(val);
			dc.SetBkColor(m_Text_Color);
			dc.TextOut(m_to*54+5, m_Rect_Heigh-2*m_Blank_Heigh-1, str);
			Sleep(val);
		}
	}
}

⌨️ 快捷键说明

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