📄 multisol.cpp
字号:
/*
Sudoku Quick and Easy Solver
Copyright (C) 2005 Suhaib Chishtie
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "stdafx.h"
#include "Sudoku.h"
#include "MultiSol.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MultiSol dialog
MultiSol::MultiSol(CWnd* pParent /*=NULL*/)
: CDialog(MultiSol::IDD, pParent)
{
//{{AFX_DATA_INIT(MultiSol)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void MultiSol::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(MultiSol)
DDX_Control(pDX, IDC_B_PREV, m_bPrev);
DDX_Control(pDX, IDC_B_NEXT, m_bNext);
DDX_Control(pDX, IDC_S_MSG, m_Msg);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(MultiSol, CDialog)
//{{AFX_MSG_MAP(MultiSol)
ON_BN_CLICKED(IDC_B_NEXT, OnBNext)
ON_BN_CLICKED(IDC_B_PREV, OnBPrev)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// MultiSol message handlers
void MultiSol::OnBNext()
{
// TODO: Add your control notification handler code here
CurrentSol++;
SetButtons();
SetSol();
}
void MultiSol::OnBPrev()
{
// TODO: Add your control notification handler code here
CurrentSol--;
SetButtons();
SetSol();
}
BOOL MultiSol::OnInitDialog()
{
unsigned j, k, startx, x, y, id;
CDialog::OnInitDialog();
// TODO: Add extra initialization here
id = 55;
startx = 10;
y = 20;
CurrentSol = 0;
for (j=0; j<9; j++){
x = startx;
for (k=0; k<9; k++){
pEdit[j][k] = new CEdit;
pEdit[j][k]->Create(ES_MULTILINE | WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
CRect(x, y, x+20, y+20), this, id);
//str.Format("%d", sol[j][k]);
//pEdit[j][k]->SetWindowText(str);
x += 20+5;
if ( !((k+1)%3) )
x+= 5;
}
y += 20+5;
if ( !((j+1)%3) )
y += 5;
}
SetButtons();
SetSol();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void MultiSol::SetButtons()
{
if (CurrentSol == NoOfSol-1)
m_bNext.EnableWindow(FALSE);
else
m_bNext.EnableWindow(TRUE);
if (CurrentSol == 0)
m_bPrev.EnableWindow(FALSE);
else
m_bPrev.EnableWindow(TRUE);
}
void MultiSol::SetSol()
{
unsigned j, k;
CString str;
unsigned int *sol, val, bm;
sol = solutions[CurrentSol];
for (j=0; j<9; j++){
for (k=0; k<9; k++){
for (val=0,bm=sol[j*9+k]; bm!=0; val++,bm>>=1);
str.Format("%d", val);
pEdit[j][k]->SetWindowText(str);
}
}
if (NoOfSol > 1)
str.Format("Solution %d of %d", CurrentSol+1, NoOfSol);
m_Msg.SetWindowText(str);
}
MultiSol::~MultiSol()
{
for (int j=0; j<9; j++)
for (int k=0; k<9; k++)
if (pEdit[j][k] != NULL)
delete pEdit[j][k];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -