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

📄 eightpuzzlesdlg.cpp

📁 利用VC开发的一个八数码程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// EightPuzzlesDlg.cpp : implementation file
//

#include "stdafx.h"
#include "EightPuzzles.h"
#include "EIGHTNUMS1.h"
#include "EightPuzzlesDlg.h"
#include "SHWRESULT.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()

/////////////////////////////////////////////////////////////////////////////
// CEightPuzzlesDlg dialog

CEightPuzzlesDlg::CEightPuzzlesDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CEightPuzzlesDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CEightPuzzlesDlg)
	m_sbinistate1 = 0;
	m_sbinistate2 = 0;
	m_sbinistate3 = 0;
	m_sbinistate4 = 0;
	m_sbinistate5 = 0;
	m_sbinistate6 = 0;
	m_sbinistate7 = 0;
	m_sbinistate8 = 0;
	m_sbinistate9 = 0;
	m_sbobjstate1 = 0;
	m_sbobjstate2 = 0;
	m_sbobjstate3 = 0;
	m_sbobjstate4 = 0;
	m_sbobjstate5 = 0;
	m_sbobjstate6 = 0;
	m_sbobjstate7 = 0;
	m_sbobjstate8 = 0;
	m_sbobjstate9 = 0;
	m_bshow = _T("");
		//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_brush.CreateSolidBrush(RGB(0,20,200));
}

void CEightPuzzlesDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CEightPuzzlesDlg)
	DDX_Text(pDX, IDC_INPUT1, m_sbinistate1);
	DDX_Text(pDX, IDC_INPUT2, m_sbinistate2);
	DDX_Text(pDX, IDC_INPUT3, m_sbinistate3);
	DDX_Text(pDX, IDC_INPUT4, m_sbinistate4);
	DDX_Text(pDX, IDC_INPUT5, m_sbinistate5);
	DDX_Text(pDX, IDC_INPUT6, m_sbinistate6);
	DDX_Text(pDX, IDC_INPUT7, m_sbinistate7);
	DDX_Text(pDX, IDC_INPUT8, m_sbinistate8);
	DDX_Text(pDX, IDC_INPUT9, m_sbinistate9);
	DDX_Text(pDX, IDC_OUTPUT1, m_sbobjstate1);
	DDX_Text(pDX, IDC_OUTPUT2, m_sbobjstate2);
	DDX_Text(pDX, IDC_OUTPUT3, m_sbobjstate3);
	DDX_Text(pDX, IDC_OUTPUT4, m_sbobjstate4);
	DDX_Text(pDX, IDC_OUTPUT5, m_sbobjstate5);
	DDX_Text(pDX, IDC_OUTPUT6, m_sbobjstate6);
	DDX_Text(pDX, IDC_OUTPUT7, m_sbobjstate7);
	DDX_Text(pDX, IDC_OUTPUT8, m_sbobjstate8);
	DDX_Text(pDX, IDC_OUTPUT9, m_sbobjstate9);
	DDX_Text(pDX, IDC_SHOW, m_bshow);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CEightPuzzlesDlg, CDialog)
	//{{AFX_MSG_MAP(CEightPuzzlesDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_SEARCH, OnSearch)
	ON_BN_CLICKED(IDC_SHOWRESULT, OnShowresult)
	ON_BN_CLICKED(IDC_EIGHTEXIT, OnEightexit)
	ON_EN_CHANGE(IDC_INPUT1, OnChangeInput1)
	ON_EN_CHANGE(IDC_INPUT2, OnChangeInput2)
	ON_EN_CHANGE(IDC_INPUT3, OnChangeInput3)
	ON_EN_CHANGE(IDC_INPUT4, OnChangeInput4)
	ON_EN_CHANGE(IDC_INPUT5, OnChangeInput5)
	ON_EN_CHANGE(IDC_INPUT6, OnChangeInput6)
	ON_EN_CHANGE(IDC_INPUT7, OnChangeInput7)
	ON_EN_CHANGE(IDC_INPUT8, OnChangeInput8)
	ON_EN_CHANGE(IDC_INPUT9, OnChangeInput9)
	ON_EN_CHANGE(IDC_OUTPUT1, OnChangeOutput1)
	ON_EN_CHANGE(IDC_OUTPUT2, OnChangeOutput2)
	ON_EN_CHANGE(IDC_OUTPUT3, OnChangeOutput3)
	ON_EN_CHANGE(IDC_OUTPUT4, OnChangeOutput4)
	ON_EN_CHANGE(IDC_OUTPUT5, OnChangeOutput5)
	ON_EN_CHANGE(IDC_OUTPUT6, OnChangeOutput6)
	ON_EN_CHANGE(IDC_OUTPUT7, OnChangeOutput7)
	ON_EN_CHANGE(IDC_OUTPUT8, OnChangeOutput8)
	ON_EN_CHANGE(IDC_OUTPUT9, OnChangeOutput9)
	ON_WM_CTLCOLOR()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CEightPuzzlesDlg message handlers

BOOL CEightPuzzlesDlg::OnInitDialog()
{
	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
		
	//CEIGHTNUMS m_bstate;
	
	

	//m_sbinistate1=1;
	//m_sbinistate2=2;
	//UpdateData(true);
	m_binidown=false;
	m_bobjdown=false;
	//CEIGHTNUMS m_bstate;
	
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CEightPuzzlesDlg::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.

void CEightPuzzlesDlg::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();
	}
}

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

//DEL void CEightPuzzlesDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
//DEL {
//DEL 	// TODO: Add your message handler code here and/or call default
//DEL 
//DEL 	CEIGHTNUMS m_bstate;
//DEL 	m_bstate.IniState.state[0][0]=m_sbinistate1;
//DEL 	m_bstate.IniState.state[0][1]=m_sbinistate2;
//DEL 	m_bstate.IniState.state[0][2]=m_sbinistate3;
//DEL 	m_bstate.IniState.state[1][0]=m_sbinistate4;
//DEL 	m_bstate.IniState.state[1][1]=m_sbinistate5;
//DEL 	m_bstate.IniState.state[1][2]=m_sbinistate6;
//DEL 	m_bstate.IniState.state[2][0]=m_sbinistate7;
//DEL 	m_bstate.IniState.state[2][1]=m_sbinistate8;
//DEL 	m_bstate.IniState.state[2][2]=m_sbinistate9;
//DEL 	UpdateData(false);
//DEL 	m_bstate.ObjState.state[0][0]=m_sbobjstate1;
//DEL 	m_bstate.ObjState.state[0][1]=m_sbobjstate2;
//DEL 	m_bstate.ObjState.state[0][2]=m_sbobjstate3;
//DEL 	m_bstate.ObjState.state[1][0]=m_sbobjstate4;
//DEL 	m_bstate.ObjState.state[1][1]=m_sbobjstate5;
//DEL 	m_bstate.ObjState.state[1][2]=m_sbobjstate6;
//DEL 	m_bstate.ObjState.state[2][0]=m_sbobjstate7;
//DEL 	m_bstate.ObjState.state[2][1]=m_sbobjstate8;
//DEL 	m_bstate.ObjState.state[2][2]=m_sbobjstate9;
//DEL 	UpdateData(false);
//DEL 	
//DEL 	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
//DEL }

void CEightPuzzlesDlg::OnSearch() 
{
	// TODO: Add your control notification handler code here
	
	//CString m_string;
	int m_bstep;
	
	//CEIGHTNUMS m_eightpuzzles;
	if(m_eightpuzzles.ComputeJiOu(&(m_eightpuzzles.IniState))!=m_eightpuzzles.ComputeJiOu(&(m_eightpuzzles.ObjState)))
	{
		MessageBox(" So sorry for there is no solution between the two states,please input again");
		UpdateData(false);
		//MessageBox("So sorry for there is no solution between the two states,please input again");
		return;
	}
	if(m_eightpuzzles.Search()==true)
	{
		//CString m_bcurstate;
		//m_bcurstate=((m_eightpuzzles.ResultList.GetCount()-1)+48)
		UpdateData(true);
		m_bshow.Format("Success,%d steps is needed",m_eightpuzzles.ResultList.GetCount()-1);
		//itoa(m_bnum,m_bpro,10);
		UpdateData(false);
		UpdateWindow();
	}
	else
	{
		//UpdateData(true);
		m_bshow.Format("for some unknown reason,failed to search,input again");
        UpdateData(false);
		UpdateWindow();
	}


	m_bstep=0;
	

}

void CEightPuzzlesDlg::OnShowresult() 
{
	// TODO: Add your control notification handler code here
	

    //CEIGHTNUMS m_eightpuzzles;
    //CSHOWRESULT m_bshowresult;
	
    //m_bshowresult.DoModal();
	//UpdateData(false);
	
	
	//UpdateData(false);
	
    //m_bshowresult.m_bprocess=m_bnum;

    
	
	//if(m_bdlg.DoModal()==IDOK)
	//{
	//m_bdlg.DoModal();
	CSHWRESULT m_bdlg;
	m_bdlg.Create(IDD_SHWRESULT);
	m_bdlg.ShowWindow(SW_SHOW);

⌨️ 快捷键说明

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