Xinqi Bao's Git
1 // sudokuDlg.cpp : implementation file
11 static char THIS_FILE
[] = __FILE__
;
23 /////////////////////////////////////////////////////////////////////////////
24 // CAboutDlg dialog used for App About
26 class CAboutDlg
: public CDialog
32 //{{AFX_DATA(CAboutDlg)
33 enum { IDD
= IDD_ABOUTBOX
};
36 // ClassWizard generated virtual function overrides
37 //{{AFX_VIRTUAL(CAboutDlg)
39 virtual void DoDataExchange(CDataExchange
* pDX
); // DDX/DDV support
44 //{{AFX_MSG(CAboutDlg)
49 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD
)
51 //{{AFX_DATA_INIT(CAboutDlg)
55 void CAboutDlg::DoDataExchange(CDataExchange
* pDX
)
57 CDialog::DoDataExchange(pDX
);
58 //{{AFX_DATA_MAP(CAboutDlg)
62 BEGIN_MESSAGE_MAP(CAboutDlg
, CDialog
)
63 //{{AFX_MSG_MAP(CAboutDlg)
64 // No message handlers
68 /////////////////////////////////////////////////////////////////////////////
71 CSudokuDlg::CSudokuDlg(CWnd
* pParent
/*=NULL*/)
72 : CDialog(CSudokuDlg::IDD
, pParent
)
74 //{{AFX_DATA_INIT(CSudokuDlg)
75 // NOTE: the ClassWizard will add member initialization here
77 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
78 m_hIcon
= AfxGetApp()->LoadIcon(IDR_MAINFRAME
);
81 void CSudokuDlg::DoDataExchange(CDataExchange
* pDX
)
83 CDialog::DoDataExchange(pDX
);
84 //{{AFX_DATA_MAP(CSudokuDlg)
85 // NOTE: the ClassWizard will add DDX and DDV calls here
89 BEGIN_MESSAGE_MAP(CSudokuDlg
, CDialog
)
90 //{{AFX_MSG_MAP(CSudokuDlg)
94 ON_BN_CLICKED(IDC_BUTTON1
, OnButton1
)
95 ON_BN_CLICKED(IDC_BUTTON2
, OnButton2
)
96 ON_BN_CLICKED(IDC_BUTTON3
, OnButton3
)
100 /////////////////////////////////////////////////////////////////////////////
101 // CSudokuDlg message handlers
103 BOOL
CSudokuDlg::OnInitDialog()
105 CDialog::OnInitDialog();
107 // Add "About..." menu item to system menu.
109 // IDM_ABOUTBOX must be in the system command range.
110 ASSERT((IDM_ABOUTBOX
& 0xFFF0) == IDM_ABOUTBOX
);
111 ASSERT(IDM_ABOUTBOX
< 0xF000);
113 CMenu
* pSysMenu
= GetSystemMenu(FALSE
);
114 if (pSysMenu
!= NULL
)
116 CString strAboutMenu
;
117 strAboutMenu
.LoadString(IDS_ABOUTBOX
);
118 if (!strAboutMenu
.IsEmpty())
120 pSysMenu
->AppendMenu(MF_SEPARATOR
);
121 pSysMenu
->AppendMenu(MF_STRING
, IDM_ABOUTBOX
, strAboutMenu
);
125 // Set the icon for this dialog. The framework does this automatically
126 // when the application's main window is not a dialog
127 SetIcon(m_hIcon
, TRUE
); // Set big icon
128 SetIcon(m_hIcon
, FALSE
); // Set small icon
130 // TODO: Add extra initialization here
132 return TRUE
; // return TRUE unless you set the focus to a control
135 void CSudokuDlg::OnSysCommand(UINT nID
, LPARAM lParam
)
137 if ((nID
& 0xFFF0) == IDM_ABOUTBOX
)
144 CDialog::OnSysCommand(nID
, lParam
);
148 // If you add a minimize button to your dialog, you will need the code below
149 // to draw the icon. For MFC applications using the document/view model,
150 // this is automatically done for you by the framework.
152 void CSudokuDlg::OnPaint()
156 CPaintDC
dc(this); // device context for painting
158 SendMessage(WM_ICONERASEBKGND
, (WPARAM
) dc
.GetSafeHdc(), 0);
160 // Center icon in client rectangle
161 int cxIcon
= GetSystemMetrics(SM_CXICON
);
162 int cyIcon
= GetSystemMetrics(SM_CYICON
);
164 GetClientRect(&rect
);
165 int x
= (rect
.Width() - cxIcon
+ 1) / 2;
166 int y
= (rect
.Height() - cyIcon
+ 1) / 2;
169 dc
.DrawIcon(x
, y
, m_hIcon
);
179 for(i_1
=0;i_1
<10;i_1
++)
181 dc
.MoveTo(20,20+40*i_1
);
182 dc
.LineTo(380,20+40*i_1
);
185 dc
.MoveTo(20,20+40*i_1
+1);
186 dc
.LineTo(380,20+40*i_1
+1);
189 for(j_1
=0;j_1
<10;j_1
++)
191 dc
.MoveTo(20+40*j_1
,20);
192 dc
.LineTo(20+40*j_1
,380);
195 dc
.MoveTo(20+40*j_1
+1,20);
196 dc
.LineTo(20+40*j_1
+1,380);
201 TextOut(dc
,460,150,"ÎÞ½â",4);
205 for(i_1
=1;i_1
<10;i_1
++)
207 for(j_1
=1;j_1
<10;j_1
++)
211 cs
.Format("%.0f",a
[i_1
][j_1
]);
212 TextOut(dc
,40*j_1
-10,40*i_1
-10,cs
,cs
.GetLength());
220 // The system calls this to obtain the cursor to display while the user drags
221 // the minimized window.
222 HCURSOR
CSudokuDlg::OnQueryDragIcon()
224 return (HCURSOR
) m_hIcon
;
227 void CSudokuDlg::OnButton1()
229 // TODO: Add your control notification handler code here
231 CFileDialog
fileDlg(TRUE
);
232 fileDlg
.m_ofn
.lpstrTitle
= "OpenFile";
233 fileDlg
.m_ofn
.lpstrFilter
= "Txt(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0";
235 CClientDC
paDC(this);
239 if(IDOK
== fileDlg
.DoModal())
241 CStdioFile
file(fileDlg
.GetFileName(),CFile::modeRead
);
242 while(file
.ReadString(strLine
))
244 //AfxMessageBox(strLine);
246 float st
=atof(strLine
);
247 a
[(i_txt
-1)/9+1][(i_txt
-1)%9+1]=st
;
249 if(i_txt
==820) break;
256 for(i_1
=1;i_1
<10;i_1
++)
258 for(j_1
=1;j_1
<10;j_1
++)
260 b
[i_1
][j_1
]=a
[i_1
][j_1
];
263 for(i_1
=1;i_1
<10;i_1
++)
265 for(j_1
=1;j_1
<10;j_1
++)
267 c
[i_1
][j_1
]=a
[i_1
][j_1
];
273 void CSudokuDlg::OnButton2()
275 // TODO: Add your control notification handler code here
277 if( times
!=0 && c
[i
][j
]==0 ) b
[i
][j
]--;
289 for(t
=b
[i
][j
]+1;t
<10;t
++)
296 if( b
[(i
-1)/3*3+1+n
/3][(j
-1)/3*3+1+n
%3]==b
[i
][j
] && (i
-1)/3*3+1+n
/3!=i
&& (j
-1)/3*3+1+n
%3!=j
)
302 if( b
[i
][n
]==b
[i
][j
] && n
!=j
)
308 if( b
[n
][j
]==b
[i
][j
] && n
!=i
)
313 if( b
[i
][j
]==9 && k
!=0 )
333 if( b
[i
][j
]==9 && k
!=0 )
341 if(times
==100000) break;
347 for(i_1
=1;i_1
<10;i_1
++)
349 for(j_1
=1;j_1
<10;j_1
++)
351 a
[i_1
][j_1
]=b
[i_1
][j_1
];
359 void CSudokuDlg::OnButton3()
361 // TODO: Add your control notification handler code here