/[projects]/SodukuSolver/test1/test1Dlg.cpp
ViewVC logotype

Contents of /SodukuSolver/test1/test1Dlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 226 - (show annotations) (download)
Mon Jun 15 11:06:35 2009 UTC (14 years, 11 months ago) by torben
File size: 4868 byte(s)


1 // test1Dlg.cpp : implementation file
2 //
3
4 #include "stdafx.h"
5 #include "test1.h"
6 #include "test1Dlg.h"
7 #include ".\test1dlg.h"
8 #include "EnterNumber.h"
9
10 #ifdef _DEBUG
11 #define new DEBUG_NEW
12 #endif
13
14
15 // Ctest1Dlg dialog
16
17
18
19 Ctest1Dlg::Ctest1Dlg(CWnd* pParent /*=NULL*/)
20 : CDialog(Ctest1Dlg::IDD, pParent)
21 {
22 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
23 }
24
25 void Ctest1Dlg::DoDataExchange(CDataExchange* pDX)
26 {
27 CDialog::DoDataExchange(pDX);
28 }
29
30 BEGIN_MESSAGE_MAP(Ctest1Dlg, CDialog)
31 ON_WM_PAINT()
32 ON_WM_QUERYDRAGICON()
33 //}}AFX_MSG_MAP
34 ON_BN_CLICKED(IDOK, OnBnClickedOk)
35 ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
36 ON_BN_CLICKED(CLEAR, OnBnClickedClear)
37 ON_WM_LBUTTONDOWN()
38 ON_BN_CLICKED(IDC_ABOUT, OnBnClickedAbout)
39 ON_BN_CLICKED(CLEARCALC, OnBnClickedClearcalc)
40 END_MESSAGE_MAP()
41
42
43 // Ctest1Dlg message handlers
44
45 BOOL Ctest1Dlg::OnInitDialog()
46 {
47 CDialog::OnInitDialog();
48
49 // Set the icon for this dialog. The framework does this automatically
50 // when the application's main window is not a dialog
51 SetIcon(m_hIcon, TRUE); // Set big icon
52 SetIcon(m_hIcon, FALSE); // Set small icon
53
54
55 return TRUE; // return TRUE unless you set the focus to a control
56 }
57
58 // If you add a minimize button to your dialog, you will need the code below
59 // to draw the icon. For MFC applications using the document/view model,
60 // this is automatically done for you by the framework.
61
62 void Ctest1Dlg::OnPaint()
63 {
64 DrawMatrix();
65
66 if (IsIconic())
67 {
68 CPaintDC dc(this); // device context for painting
69
70 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
71
72 // Center icon in client rectangle
73 int cxIcon = GetSystemMetrics(SM_CXICON);
74 int cyIcon = GetSystemMetrics(SM_CYICON);
75 CRect rect;
76 GetClientRect(&rect);
77 int x = (rect.Width() - cxIcon + 1) / 2;
78 int y = (rect.Height() - cyIcon + 1) / 2;
79
80 // Draw the icon
81 dc.DrawIcon(x, y, m_hIcon);
82 }
83 else
84 {
85 CDialog::OnPaint();
86 }
87 }
88
89 // The system calls this function to obtain the cursor to display while the user drags
90 // the minimized window.
91 HCURSOR Ctest1Dlg::OnQueryDragIcon()
92 {
93 return static_cast<HCURSOR>(m_hIcon);
94 }
95
96 void Ctest1Dlg::OnBnClickedOk()
97 {
98 OnOK();
99 }
100
101 void Ctest1Dlg::OnBnClickedButton1()
102 {
103 try {
104 m_sudoku.solve();
105 } catch (...) {
106 MessageBox("This problem can not be solved");
107 }
108
109 Invalidate();
110 this->UpdateWindow();
111 }
112
113
114
115 void Ctest1Dlg::OnBnClickedClear()
116 {
117 m_sudoku.clear();
118 Invalidate();
119 this->UpdateWindow();
120 }
121
122 void Ctest1Dlg::OnBnClickedClearcalc()
123 {
124 m_sudoku.clearCalculated();
125 Invalidate();
126 this->UpdateWindow();
127 }
128
129
130
131
132 void Ctest1Dlg::OnLButtonDown(UINT nFlags, CPoint point)
133 {
134 int x,y;
135 int result;
136 // TODO: Add your message handler code here and/or call default
137 if (point.x >25 && point.x < 290 && point.y > 25 && point.y <290) {
138 x = (point.x-25) / 30;
139 y = (point.y-25) / 30;
140 EnterNumber en(0);
141 en.DoModal();
142
143 result = en.number();
144 m_sudoku.setNumber(x,y,result);
145
146 this->Invalidate();
147 this->UpdateWindow();
148 }
149
150 CDialog::OnLButtonDown(nFlags, point);
151 }
152
153 void Ctest1Dlg::OnBnClickedAbout()
154 {
155 MessageBox("Sudoku Solver (C) 2006-2007 by Torben H. Nielsen");
156 }
157
158 void Ctest1Dlg::OnOK()
159 {
160 // TODO: Add your specialized code here and/or call the base class
161 CDialog::OnOK();
162 }
163
164 void Ctest1Dlg::OnCancel()
165 {
166 // TODO: Add your specialized code here and/or call the base class
167 OnOK();
168 }
169
170 void Ctest1Dlg::DrawMatrix(void)
171 {
172 int i,j;
173 int startx,starty,stopx,stopy;
174 CPaintDC paint(this);
175
176 paint.SetBkMode(TRANSPARENT);
177 CPen thinpen(PS_SOLID, 1, RGB(0,0,0) );
178 CPen thickpen(PS_SOLID, 3, RGB(0,0,0) );
179 CBrush whitebrush(RGB(255,255,255));
180 RECT area;
181 area.top = 10;
182 area.bottom = 310;
183 area.left = 10;
184 area.right = 310;
185 paint.FillRect(&area,&whitebrush);
186
187 //Draw horizontal lines
188 for(i=0; i<10; i++) {
189 if (i%3==0)
190 paint.SelectObject(&thickpen);
191 else
192 paint.SelectObject(&thinpen);
193 startx = 15;
194 stopx = 305;
195 starty = stopy = (i*30) + 25;
196 paint.MoveTo(startx,starty);
197 paint.LineTo(stopx,stopy);
198 }
199
200
201 //Draw vertical lines
202 for(i=0; i<10; i++) {
203 if (i%3==0)
204 paint.SelectObject(&thickpen);
205 else
206 paint.SelectObject(&thinpen);
207 starty = 15;
208 stopy = 305;
209 startx = stopx = (i*30) + 25;
210 paint.MoveTo(startx,starty);
211 paint.LineTo(stopx,stopy);
212 }
213 paint.SelectObject(&thinpen);
214
215 //Fill the matrix with the numbers
216 for (i=0; i<9;i++) {
217 for (j=0; j<9; j++) {
218 if ( m_sudoku.getNumber(i,j) > 0 ) {
219 if (m_sudoku.getUser(i,j))
220 paint.SetTextColor(RGB(0,0,255));
221 else
222 paint.SetTextColor(RGB(0,0,0));
223 CString tmp;
224 tmp.Format("%d", m_sudoku.getNumber(i,j));
225 paint.TextOut((i*30)+36,(j*30)+33, tmp);
226
227 }
228 }
229 }
230
231 }
232
233

  ViewVC Help
Powered by ViewVC 1.1.20