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

📄 eightnumdlg.cpp

📁 可能这个程序有的功能还没有解决 仅供参考
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	// TODO: Add your control notification handler code here
	ClickNum(1,2);
}

void CEightNumDlg::OnBtn7() 
{
	// TODO: Add your control notification handler code here
	ClickNum(2,0);
}

void CEightNumDlg::OnBtn8() 
{
	// TODO: Add your control notification handler code here
	ClickNum(2,1);
}

void CEightNumDlg::OnBtn9() 
{
	// TODO: Add your control notification handler code here
	ClickNum(2,2);
}

void CEightNumDlg::GetSpacePos(int& x,int& y)
{
	for(x=0;x<3;x++)
		for(y=0;y<3;y++)
			if(m_byBoard[x][y]==0)
				return;
}

void CEightNumDlg::OnBtnAutosolve() 
{
	// TODO: Add your control notification handler code here
	if(m_pSearchEngine)
		delete m_pSearchEngine;
	switch(m_iSearchEngine)
	{
	case 0:
		m_pSearchEngine=new CGSESearchEngine;
		break;

	case 1:
		m_pSearchEngine=new CGSE_TTSearchEngine;
		break;
	}

	m_pSearchEngine->SearchAGoodMove(m_byBoard);
	m_pSearchEngine->m_stackBestMove.pop();

	SetTimer(ID_SOLVE,500,NULL);
	UpdateBoard(m_byBoard);
}

void CEightNumDlg::UpdateBoard(BYTE byBoard[][3])
{
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			switch(byBoard[i][j])
			{
			case 0:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(0);
				break;

			case 1:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(m_bitmapBtn4);
				break;

			case 2:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(m_bitmapBtn1);
				break;

			case 3:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(m_bitmapBtn3);
				break;

			case 4:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(m_bitmapBtn6);
				break;

			case 5:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(m_bitmapBtn9);
				break;

			case 6:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(m_bitmapBtn5);
				break;

			case 7:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(m_bitmapBtn7);
				break;

			case 8:
				((CButton*)GetDlgItem(m_iBtnID[i][j]))->SetBitmap(m_bitmapBtn2);
				break;
		}

}

void CEightNumDlg::OnOpen() 
{
	// TODO: Add your command handler code here
	CFileDialog m_OpenDlg(TRUE,NULL,"",0,"八数码难题(*.*)|*.*||");
	
	if(m_OpenDlg.DoModal()==IDCANCEL) 
		return;

	CString strCMFile;
	char* pCMFile;
	FILE* fp;
	int i,j;

	strCMFile=m_OpenDlg.GetPathName();
	pCMFile=(LPSTR)(LPCTSTR)strCMFile;

	fp=fopen(pCMFile,"r");
	if(fp==NULL)
	{
		MessageBox("打开文件出错","错误提示",MB_ICONWARNING);
		return;
	}

	if(MessageBox("是否覆盖当前问题?","友情提醒",MB_YESNO | MB_ICONQUESTION)==IDNO)
		return;

	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
			fscanf(fp,"%3d",&m_byBoard[i][j]);

	fclose(fp);
	UpdateBoard(m_byBoard);
}

void CEightNumDlg::OnSave() 
{
	// TODO: Add your command handler code here
	CFileDialog m_SaveDlg(false,NULL,"",0,"八数码难题(*.*)|*.*||");
	
	if(m_SaveDlg.DoModal()==IDCANCEL) 
		return;

	CString strCMFile;
	char* pCMFile;
	FILE* fp;
	int i,j;

	strCMFile=m_SaveDlg.GetPathName();
	pCMFile=(LPSTR)(LPCTSTR)strCMFile;

	fp=fopen(pCMFile,"w");
	if(fp==NULL)
	{
		MessageBox("打开文件出错","错误提示",MB_ICONWARNING);
		return;
	}

	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
			fprintf(fp,"%-3d",m_byBoard[i][j]);
		fprintf(fp,"\n");
	}

	fclose(fp);
}

void CEightNumDlg::OnExit() 
{
	// TODO: Add your command handler code here
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_BLEND);
	EndDialog(IDOK);
}

void CEightNumDlg::OnBtnExit() 
{
	// TODO: Add your control notification handler code here
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_BLEND);
	EndDialog(IDOK);
}

void CEightNumDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent==ID_SOLVE)
	{
		UpdateBoard(m_pSearchEngine->m_stackBestMove.top().byBoard);
		memcpy(m_byTemp,m_pSearchEngine->m_stackBestMove.top().byBoard,9);
		m_pSearchEngine->m_stackBestMove.pop();
		if(m_pSearchEngine->m_stackBestMove.empty())
		{
			m_staticTip.SetWindowText("难题求解完毕,请验收");
			KillTimer(ID_SOLVE);
			memcpy(m_byBoard,m_byTemp,9);
		}
	}

	CDialog::OnTimer(nIDEvent);
}

void CEightNumDlg::OnBtnBegin() 
{
	// TODO: Add your control notification handler code here
	int i,j,k=0;
	BYTE a[9];

	srand((unsigned)time(NULL));
	for(i=0;i<9;i++)
	{
		a[i]=rand()%9;
		do					
		a[i]=rand()%9;
		while(IsIn(a,i));
	}

	for(i=0;i<3;i++)
		for(j=0;j<3;j++)
		{
			m_byBoard[i][j]=a[k];
			k++;
		}

	UpdateBoard(m_byBoard);
}

bool CEightNumDlg::IsIn(BYTE a[],int i)
{
	for(int j=0;j<i;j++)
		if(a[j]==a[i])
			return 1;

	return 0;
}

void CEightNumDlg::OnBtnOpen() 
{
	// TODO: Add your control notification handler code here
	OnOpen();
}

void CEightNumDlg::OnBtnSave() 
{
	// TODO: Add your control notification handler code here
	OnSave();
}

void CEightNumDlg::OnHelp() 
{
	// TODO: Add your command handler code here
	CHelpDlg dlg;
	dlg.DoModal();
}

void CEightNumDlg::OnAbout() 
{
	// TODO: Add your command handler code here
	CAboutDlg dlg;
	dlg.DoModal();
}

void CEightNumDlg::OnRand() 
{
	// TODO: Add your command handler code here
	OnBtnBegin();
}

void CEightNumDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_BLEND);

	CDialog::OnClose();
}

void CAboutDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_BLEND);

	CDialog::OnClose();
}

void CAboutDlg::OnOK() 
{
	// TODO: Add extra validation here
	AnimateWindow(GetSafeHwnd(),1000,AW_HIDE|AW_BLEND);
	CDialog::OnOK();
}

BOOL CEightNumDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_tooltip.RelayEvent(pMsg); 

	return CDialog::PreTranslateMessage(pMsg);
}

void CEightNumDlg::WinHelp(DWORD dwData, UINT nCmd) 
{
	// TODO: Add your specialized code here and/or call the base class
	CHelpDlg dlg;
	dlg.DoModal();
}

BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_staticMail.SetMail("ahei080210114@hotmail.com");
	m_ToolTip.Create(this);
	m_ToolTip.Activate(1);
	m_ToolTip.AddTool(GetDlgItem(IDC_STATIC_QQ),"单击复制我的QQ号");

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BOOL CAboutDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	m_ToolTip.RelayEvent(pMsg);

	return CDialog::PreTranslateMessage(pMsg);
}

void CAboutDlg::OnStaticQq() 
{
	// TODO: Add your control notification handler code here
	CString str="8261525"; 
	HGLOBAL h=GlobalAlloc(GHND | GMEM_SHARE,str.GetLength()+1); 

	::OpenClipboard(this->m_hWnd); 
	::EmptyClipboard();
	
	strcpy((LPSTR)GlobalLock(h),str); 
	GlobalUnlock(h); 
	::SetClipboardData(CF_TEXT,h); 
	::CloseClipboard(); 
}

void CEightNumDlg::OnSet() 
{
	// TODO: Add your command handler code here
	if(m_SetDlg.DoModal()!=IDOK)
		return;

	m_iSearchEngine=m_SetDlg.GetSearchEngine();
}

⌨️ 快捷键说明

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