[Win32k]
[reactos.git] / base / applications / games / solitaire / solitaire.cpp
1 #include "solitaire.h"
2
3 #include <winreg.h>
4 #include <commctrl.h>
5 #include <tchar.h>
6
7 #include "resource.h"
8
9 TCHAR szHelpPath[MAX_PATH];
10
11 DWORD dwAppStartTime;
12 HWND hwndMain;
13 HWND hwndStatus;
14 HINSTANCE hInstance;
15
16 TCHAR szAppName[128];
17 TCHAR szScore[64];
18 TCHAR szTime[64];
19 TCHAR MsgQuit[128];
20 TCHAR MsgAbout[128];
21 TCHAR MsgWin[128];
22 TCHAR MsgDeal[128];
23 DWORD dwOptions = OPTION_THREE_CARDS;
24
25 DWORD dwTime;
26 DWORD dwWasteCount;
27 DWORD dwWasteTreshold;
28 DWORD dwPrevMode;
29 long lScore;
30 UINT_PTR PlayTimer = 0;
31
32 CardWindow SolWnd;
33
34 typedef struct _CardBack
35 {
36 HWND hSelf;
37 WNDPROC hOldProc;
38 INT hdcNum;
39 INT imgNum;
40 BOOL bSelected;
41 } CARDBACK, *PCARDBACK;
42
43 LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
44
45 void MakePath(TCHAR *szDest, UINT nDestLen, const TCHAR *szExt)
46 {
47 TCHAR *ptr;
48
49 ptr = szDest + GetModuleFileName(GetModuleHandle(0), szDest, nDestLen) - 1;
50 while(*ptr-- != '.');
51 lstrcpy(ptr + 1, szExt);
52 }
53
54 VOID LoadSettings(VOID)
55 {
56 DWORD dwDisposition;
57 DWORD dwSize;
58 DWORD dwBack;
59 HKEY hKey;
60
61 if (RegCreateKeyEx(HKEY_CURRENT_USER,
62 _T("Software\\ReactOS\\Solitaire"),
63 0,
64 NULL,
65 REG_OPTION_NON_VOLATILE,
66 KEY_READ,
67 NULL,
68 &hKey,
69 &dwDisposition))
70 return;
71
72 dwSize = sizeof(DWORD);
73 RegQueryValueEx(hKey,
74 _T("Options"),
75 NULL,
76 NULL,
77 (LPBYTE)&dwOptions,
78 &dwSize);
79
80 dwSize = sizeof(DWORD);
81 RegQueryValueEx(hKey,
82 _T("Back"),
83 NULL,
84 NULL,
85 (LPBYTE)&dwBack,
86 &dwSize);
87 SolWnd.SetBackCardIdx(dwBack);
88
89 RegCloseKey(hKey);
90 }
91
92 VOID SaveSettings(VOID)
93 {
94 DWORD dwDisposition;
95 DWORD dwBack;
96 HKEY hKey;
97
98 if (RegCreateKeyEx(HKEY_CURRENT_USER,
99 _T("Software\\ReactOS\\Solitaire"),
100 0,
101 NULL,
102 REG_OPTION_NON_VOLATILE,
103 KEY_WRITE,
104 NULL,
105 &hKey,
106 &dwDisposition))
107 return;
108
109 RegSetValueEx(hKey,
110 _T("Options"),
111 0,
112 REG_DWORD,
113 (CONST BYTE *)&dwOptions,
114 sizeof(DWORD));
115
116 dwBack = SolWnd.GetBackCardIdx();
117 RegSetValueEx(hKey,
118 _T("Back"),
119 0,
120 REG_DWORD,
121 (CONST BYTE *)&dwBack,
122 sizeof(DWORD));
123
124 RegCloseKey(hKey);
125 }
126
127 // Returns 0 for no points, 1 for Standard and 2 for Vegas
128 int GetScoreMode(void)
129 {
130 if ((dwOptions & OPTION_SCORE_STD) && (dwOptions & OPTION_SCORE_VEGAS))
131 {
132 return SCORE_NONE;
133 }
134
135 if (dwOptions & OPTION_SCORE_STD)
136 {
137 return SCORE_STD;
138 }
139
140 if (dwOptions & OPTION_SCORE_VEGAS)
141 {
142 return SCORE_VEGAS;
143 }
144
145 return 0;
146 }
147
148 void UpdateStatusBar(void)
149 {
150 TCHAR szStatusText[128];
151 TCHAR szTempText[64];
152
153 ZeroMemory(szStatusText, sizeof(szStatusText) / sizeof(TCHAR));
154
155 if (GetScoreMode() != SCORE_NONE)
156 {
157 _stprintf(szStatusText, szScore, lScore);
158 _tcscat(szStatusText, _T(" "));
159 }
160
161 if (dwOptions & OPTION_SHOW_TIME)
162 {
163 _stprintf(szTempText, szTime, dwTime);
164 _tcscat(szStatusText, szTempText);
165 }
166
167 SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)(LPTSTR)szStatusText);
168 }
169
170 void SetPlayTimer(void)
171 {
172 if (dwOptions & OPTION_SHOW_TIME)
173 {
174 if (!PlayTimer)
175 {
176 PlayTimer = SetTimer(hwndMain, IDT_PLAYTIMER, 1000, NULL);
177 }
178 }
179 }
180
181 //
182 // Main entry point
183 //
184 int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int iCmdShow)
185 {
186 HWND hwnd;
187 MSG msg;
188 WNDCLASS wndclass;
189 INITCOMMONCONTROLSEX ice;
190 HACCEL hAccelTable;
191
192 hInstance = hInst;
193
194 // Load application title
195 LoadString(hInst, IDS_SOL_NAME, szAppName, sizeof(szAppName) / sizeof(szAppName[0]));
196 // Load MsgBox() texts here to avoid loading them many times later
197 LoadString(hInst, IDS_SOL_ABOUT, MsgAbout, sizeof(MsgAbout) / sizeof(MsgAbout[0]));
198 LoadString(hInst, IDS_SOL_QUIT, MsgQuit, sizeof(MsgQuit) / sizeof(MsgQuit[0]));
199 LoadString(hInst, IDS_SOL_WIN, MsgWin, sizeof(MsgWin) / sizeof(MsgWin[0]));
200 LoadString(hInst, IDS_SOL_DEAL, MsgDeal, sizeof(MsgDeal) / sizeof(MsgDeal[0]));
201
202 LoadString(hInst, IDS_SOL_SCORE, szScore, sizeof(szScore) / sizeof(TCHAR));
203 LoadString(hInst, IDS_SOL_TIME, szTime, sizeof(szTime) / sizeof(TCHAR));
204
205 //Window class for the main application parent window
206 wndclass.style = 0;//CS_HREDRAW | CS_VREDRAW;
207 wndclass.lpfnWndProc = WndProc;
208 wndclass.cbClsExtra = 0;
209 wndclass.cbWndExtra = 0;
210 wndclass.hInstance = hInst;
211 wndclass.hIcon = LoadIcon (hInst, MAKEINTRESOURCE(IDI_SOLITAIRE));
212 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
213 wndclass.hbrBackground = (HBRUSH)NULL;
214 wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
215 wndclass.lpszClassName = szAppName;
216
217 RegisterClass(&wndclass);
218
219 ice.dwSize = sizeof(ice);
220 ice.dwICC = ICC_BAR_CLASSES;
221 InitCommonControlsEx(&ice);
222
223 srand((unsigned)GetTickCount());//timeGetTime());
224
225 // InitCardLib();
226
227 LoadSettings();
228
229 dwPrevMode = GetScoreMode();
230
231 //Construct the path to our help file
232 MakePath(szHelpPath, MAX_PATH, _T(".hlp"));
233
234 hwnd = CreateWindow(szAppName, // window class name
235 szAppName, // window caption
236 WS_OVERLAPPEDWINDOW
237 ,//|WS_CLIPCHILDREN, // window style
238 CW_USEDEFAULT, // initial x position
239 CW_USEDEFAULT, // initial y position
240 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
241 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
242 NULL, // parent window handle
243 NULL, // use window class menu
244 hInst, // program instance handle
245 NULL); // creation parameters
246
247 hwndMain = hwnd;
248
249 UpdateStatusBar();
250
251 ShowWindow(hwnd, iCmdShow);
252 UpdateWindow(hwnd);
253
254 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1));
255
256 while(GetMessage(&msg, NULL,0,0))
257 {
258 if(!TranslateAccelerator(hwnd, hAccelTable, &msg))
259 {
260 TranslateMessage(&msg);
261 DispatchMessage(&msg);
262 }
263 }
264
265 SaveSettings();
266
267 return msg.wParam;
268 }
269
270
271 INT_PTR CALLBACK OptionsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
272 {
273 HWND hCtrl;
274
275 switch (uMsg)
276 {
277 case WM_INITDIALOG:
278 CheckRadioButton(hDlg, IDC_OPT_DRAWONE, IDC_OPT_DRAWTHREE,
279 (dwOptions & OPTION_THREE_CARDS) ? IDC_OPT_DRAWTHREE : IDC_OPT_DRAWONE);
280
281 CheckDlgButton(hDlg,
282 IDC_OPT_STATUSBAR,
283 (dwOptions & OPTION_SHOW_STATUS) ? BST_CHECKED : BST_UNCHECKED);
284
285 CheckDlgButton(hDlg,
286 IDC_OPT_SHOWTIME,
287 (dwOptions & OPTION_SHOW_TIME) ? BST_CHECKED : BST_UNCHECKED);
288
289 CheckDlgButton(hDlg,
290 IDC_OPT_KEEPSCORE,
291 (dwOptions & OPTION_KEEP_SCORE) ? BST_CHECKED : BST_UNCHECKED);
292
293 hCtrl = GetDlgItem(hDlg, IDC_OPT_KEEPSCORE);
294
295 if (GetScoreMode() == SCORE_NONE)
296 {
297 CheckRadioButton(hDlg, IDC_OPT_STANDARD, IDC_OPT_NOSCORE, IDC_OPT_NOSCORE);
298 EnableWindow(hCtrl, FALSE);
299 }
300 else if (GetScoreMode() == SCORE_STD)
301 {
302 CheckRadioButton(hDlg, IDC_OPT_STANDARD, IDC_OPT_NOSCORE, IDC_OPT_STANDARD);
303 EnableWindow(hCtrl, FALSE);
304 }
305 else if (GetScoreMode() == SCORE_VEGAS)
306 {
307 CheckRadioButton(hDlg, IDC_OPT_STANDARD, IDC_OPT_NOSCORE, IDC_OPT_VEGAS);
308 EnableWindow(hCtrl, TRUE);
309 }
310 return TRUE;
311
312 case WM_COMMAND:
313 switch(LOWORD(wParam))
314 {
315 case IDC_OPT_NOSCORE:
316 case IDC_OPT_STANDARD:
317 case IDC_OPT_VEGAS:
318 hCtrl = GetDlgItem(hDlg, IDC_OPT_KEEPSCORE);
319 if (wParam == IDC_OPT_VEGAS)
320 EnableWindow(hCtrl, TRUE);
321 else
322 EnableWindow(hCtrl, FALSE);
323 return TRUE;
324
325 case IDOK:
326 dwOptions &= ~OPTION_THREE_CARDS;
327 if (IsDlgButtonChecked(hDlg, IDC_OPT_DRAWTHREE) == BST_CHECKED)
328 dwOptions |= OPTION_THREE_CARDS;
329
330 if (IsDlgButtonChecked(hDlg, IDC_OPT_STATUSBAR) == BST_CHECKED)
331 dwOptions |= OPTION_SHOW_STATUS;
332 else
333 dwOptions &= ~OPTION_SHOW_STATUS;
334
335 if (IsDlgButtonChecked(hDlg, IDC_OPT_SHOWTIME) == BST_CHECKED)
336 dwOptions |= OPTION_SHOW_TIME;
337 else
338 dwOptions &= ~OPTION_SHOW_TIME;
339
340 if (IsDlgButtonChecked(hDlg, IDC_OPT_KEEPSCORE) == BST_CHECKED)
341 dwOptions |= OPTION_KEEP_SCORE;
342 else
343 dwOptions &= ~OPTION_KEEP_SCORE;
344
345 if (IsDlgButtonChecked(hDlg, IDC_OPT_STANDARD) == BST_CHECKED)
346 {
347 dwOptions |= OPTION_SCORE_STD;
348 dwOptions &= ~OPTION_SCORE_VEGAS;
349 }
350 else if (IsDlgButtonChecked(hDlg, IDC_OPT_VEGAS) == BST_CHECKED)
351 {
352 dwOptions |= OPTION_SCORE_VEGAS;
353 dwOptions &= ~OPTION_SCORE_STD;
354 }
355 else if (IsDlgButtonChecked(hDlg, IDC_OPT_NOSCORE) == BST_CHECKED)
356 {
357 dwOptions |= OPTION_SCORE_VEGAS;
358 dwOptions |= OPTION_SCORE_STD;
359 }
360
361 UpdateStatusBar();
362
363 EndDialog(hDlg, TRUE);
364 return TRUE;
365
366 case IDCANCEL:
367 EndDialog(hDlg, FALSE);
368 return TRUE;
369 }
370 break;
371 }
372 return FALSE;
373 }
374
375 VOID ShowGameOptionsDlg(HWND hwnd)
376 {
377 DWORD dwOldOptions = dwOptions;
378 RECT rcMain, rcStatus;
379
380 int iOldScoreMode = GetScoreMode();
381
382 if (DialogBox(hInstance, MAKEINTRESOURCE(IDD_OPTIONS), hwnd, OptionsDlgProc))
383 {
384 if (((dwOldOptions & OPTION_THREE_CARDS) != (dwOptions & OPTION_THREE_CARDS)) ||
385 ((dwOldOptions & OPTION_SHOW_TIME) != (dwOptions & OPTION_SHOW_TIME)) ||
386 (iOldScoreMode != GetScoreMode()))
387 NewGame();
388
389 if ((dwOldOptions & OPTION_SHOW_STATUS) != (dwOptions & OPTION_SHOW_STATUS))
390 {
391 int nWidth, nHeight, nStatusHeight;
392
393 GetClientRect(hwndMain, &rcMain);
394 nHeight = rcMain.bottom - rcMain.top;
395 nWidth = rcMain.right - rcMain.left;
396
397 if (dwOptions & OPTION_SHOW_STATUS)
398 {
399 RECT rc;
400
401 ShowWindow(hwndStatus, SW_SHOW);
402 GetWindowRect(hwndStatus, &rcStatus);
403 nStatusHeight = rcStatus.bottom - rcStatus.top;
404 MoveWindow(SolWnd, 0, 0, nWidth, nHeight-nStatusHeight, TRUE);
405 MoveWindow(hwndStatus, 0, nHeight-nStatusHeight, nWidth, nHeight, TRUE);
406
407 // Force the window to process WM_GETMINMAXINFO again
408 GetWindowRect(hwndMain, &rc);
409 SetWindowPos(hwndMain, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER);
410 }
411 else
412 {
413 ShowWindow(hwndStatus, SW_HIDE);
414 MoveWindow(SolWnd, 0, 0, nWidth, nHeight, TRUE);
415 }
416 }
417 }
418 }
419
420
421 LRESULT CALLBACK
422 CardImageWndProc(HWND hwnd,
423 UINT msg,
424 WPARAM wParam,
425 LPARAM lParam)
426 {
427 PCARDBACK pCardBack = (PCARDBACK)GetWindowLongPtr(hwnd,
428 GWL_USERDATA);
429 static WNDPROC hOldProc = NULL;
430
431 if (!hOldProc && pCardBack)
432 hOldProc = pCardBack->hOldProc;
433
434 switch (msg)
435 {
436 case WM_PAINT:
437 {
438 HDC hdc;
439 PAINTSTRUCT ps;
440 HPEN hPen, hOldPen;
441 HBRUSH hBrush, hOldBrush;
442 RECT rc;
443
444 hdc = BeginPaint(hwnd, &ps);
445
446 if (pCardBack->bSelected)
447 {
448 hPen = CreatePen(PS_SOLID, 2, RGB(0,0,0));
449 }
450 else
451 {
452 DWORD Face = GetSysColor(COLOR_3DFACE);
453 hPen = CreatePen(PS_SOLID, 2, Face);
454 }
455
456 GetClientRect(hwnd, &rc);
457 hBrush = (HBRUSH)GetStockObject(NULL_BRUSH);
458 hOldPen = (HPEN)SelectObject(hdc, hPen);
459 hOldBrush = (HBRUSH)SelectObject(hdc, hBrush);
460
461 Rectangle(hdc,
462 rc.left+1,
463 rc.top+1,
464 rc.right,
465 rc.bottom);
466
467 StretchBlt(hdc,
468 2,
469 2,
470 CARDBACK_OPTIONS_WIDTH,
471 CARDBACK_OPTIONS_HEIGHT,
472 __hdcCardBitmaps,
473 pCardBack->hdcNum * __cardwidth,
474 0,
475 __cardwidth,
476 __cardheight,
477 SRCCOPY);
478
479 SelectObject(hdc, hOldPen);
480 SelectObject(hdc, hOldBrush);
481
482 EndPaint(hwnd, &ps);
483
484 break;
485 }
486
487 case WM_LBUTTONDOWN:
488 pCardBack->bSelected = pCardBack->bSelected ? FALSE : TRUE;
489 break;
490 }
491
492 return CallWindowProc(hOldProc,
493 hwnd,
494 msg,
495 wParam,
496 lParam);
497 }
498
499
500 INT_PTR CALLBACK CardBackDlgProc(HWND hDlg,
501 UINT uMsg,
502 WPARAM wParam,
503 LPARAM lParam)
504 {
505 static PCARDBACK pCardBacks = NULL;
506
507 switch (uMsg)
508 {
509 case WM_INITDIALOG:
510 {
511 INT i, c;
512 SIZE_T size = sizeof(CARDBACK) * NUM_CARDBACKS;
513
514 pCardBacks = (PCARDBACK)HeapAlloc(GetProcessHeap(),
515 0,
516 size);
517
518 for (i = 0, c = CARDBACK_START; c <= CARDBACK_END; i++, c++)
519 {
520 pCardBacks[i].hSelf = GetDlgItem(hDlg, c);
521 pCardBacks[i].bSelected = FALSE;
522 pCardBacks[i].hdcNum = CARDBACK_RES_START + i;
523 pCardBacks[i].imgNum = i + 1;
524 pCardBacks[i].hOldProc = (WNDPROC)SetWindowLongPtr(pCardBacks[i].hSelf,
525 GWLP_WNDPROC,
526 (LONG_PTR)CardImageWndProc);
527
528 SetWindowLongPtr(pCardBacks[i].hSelf,
529 GWL_USERDATA,
530 (LONG_PTR)&pCardBacks[i]);
531 }
532
533 return TRUE;
534 }
535
536 case WM_COMMAND:
537 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
538 {
539 INT i, num = 0;
540 for (i = 0; i < NUM_CARDBACKS; i++)
541 {
542 if (pCardBacks[i].bSelected)
543 {
544 num = pCardBacks[i].imgNum;
545 }
546 }
547
548 EndDialog(hDlg, LOWORD(wParam) == IDOK ? num : FALSE);
549 HeapFree(GetProcessHeap(), 0, pCardBacks);
550 return TRUE;
551 }
552
553 if (HIWORD(wParam) == STN_CLICKED)
554 {
555 INT i;
556 RECT rc;
557 for (i = 0; i < NUM_CARDBACKS; i++)
558 {
559 if (pCardBacks[i].hSelf == (HWND)lParam)
560 {
561 pCardBacks[i].bSelected = TRUE;
562 }
563 else
564 pCardBacks[i].bSelected = FALSE;
565
566 GetClientRect(pCardBacks[i].hSelf, &rc);
567 InvalidateRect(pCardBacks[i].hSelf, &rc, TRUE);
568 }
569
570 break;
571 }
572 }
573
574 return FALSE;
575 }
576
577
578 VOID ShowDeckOptionsDlg(HWND hwnd)
579 {
580 INT cardBack;
581
582 if ((cardBack = DialogBox(hInstance,
583 MAKEINTRESOURCE(IDD_CARDBACK),
584 hwnd,
585 CardBackDlgProc)))
586 {
587 SolWnd.SetBackCardIdx(CARDBACK_RES_START + (cardBack - 1));
588 SolWnd.Redraw();
589 }
590 }
591
592 //-----------------------------------------------------------------------------
593 LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
594 {
595 static int nWidth, nHeight, nStatusHeight;
596
597 switch(iMsg)
598 {
599 case WM_CREATE:
600 {
601 int parts[] = { 150, -1 };
602 RECT rcStatus;
603
604 hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, _T("Ready"), hwnd, 0);
605
606 //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
607
608 SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
609 SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)"");
610
611 SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0);
612
613 CreateSol();
614
615 // The status bar height is fixed and needed later in WM_SIZE and WM_GETMINMAXINFO
616 // Force the window to process WM_GETMINMAXINFO again
617 GetWindowRect(hwndStatus, &rcStatus);
618 nStatusHeight = rcStatus.bottom - rcStatus.top;
619
620 // Hide status bar if options say so
621 if (!(dwOptions & OPTION_SHOW_STATUS))
622 {
623 ShowWindow(hwndStatus, SW_HIDE);
624 }
625
626 SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER);
627
628 NewGame();
629
630 dwAppStartTime = GetTickCount();
631
632 return 0;
633 }
634
635 case WM_DESTROY:
636 PostQuitMessage(0);
637 return 0;
638
639 case WM_TIMER:
640 if (!fGameStarted)
641 {
642 KillTimer(hwndMain, IDT_PLAYTIMER);
643 PlayTimer = 0;
644 }
645 else if (dwOptions & OPTION_SHOW_TIME)
646 {
647 if (((dwTime + 1) % 10 == 0) && (GetScoreMode() == SCORE_STD))
648 {
649 lScore = lScore >= 2 ? lScore - 2 : 0;
650 }
651
652 dwTime++;
653 }
654
655 UpdateStatusBar();
656 return 0;
657
658 case WM_SIZE:
659 nWidth = LOWORD(lParam);
660 nHeight = HIWORD(lParam);
661
662 if (dwOptions & OPTION_SHOW_STATUS)
663 {
664 MoveWindow(SolWnd, 0, 0, nWidth, nHeight - nStatusHeight, TRUE);
665 MoveWindow(hwndStatus, 0, nHeight - nStatusHeight, nWidth, nStatusHeight, TRUE);
666 }
667 else
668 {
669 MoveWindow(SolWnd, 0, 0, nWidth, nHeight, TRUE);
670 }
671 //parts[0] = nWidth - 256;
672 //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
673 return 0;
674
675 case WM_GETMINMAXINFO:
676 {
677 MINMAXINFO *mmi;
678
679 mmi = (MINMAXINFO *)lParam;
680 mmi->ptMinTrackSize.x = X_BORDER + NUM_ROW_STACKS * (__cardwidth + X_ROWSTACK_BORDER) + X_BORDER;
681 mmi->ptMinTrackSize.y = GetSystemMetrics(SM_CYCAPTION) +
682 GetSystemMetrics(SM_CYMENU) +
683 Y_BORDER +
684 __cardheight +
685 Y_ROWSTACK_BORDER +
686 6 * yRowStackCardOffset +
687 __cardheight +
688 Y_BORDER +
689 (dwOptions & OPTION_SHOW_STATUS ? nStatusHeight : 0);
690 return 0;
691 }
692
693 case WM_COMMAND:
694 switch(LOWORD(wParam))
695 {
696 case IDM_GAME_NEW:
697 //simulate a button click on the new button..
698 NewGame();
699 return 0;
700
701 case IDM_GAME_DECK:
702 ShowDeckOptionsDlg(hwnd);
703 return 0;
704
705 case IDM_GAME_OPTIONS:
706 ShowGameOptionsDlg(hwnd);
707 return 0;
708
709 case IDM_HELP_CONTENTS:
710 WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play");
711 return 0;
712
713 case IDM_HELP_ABOUT:
714 MessageBox(hwnd, MsgAbout, szAppName, MB_OK|MB_ICONINFORMATION);
715 return 0;
716
717 case IDM_GAME_EXIT:
718 PostMessage(hwnd, WM_CLOSE, 0, 0);
719 return 0;
720 }
721
722 return 0;
723
724 case WM_CLOSE:
725 if (fGameStarted == false)
726 {
727 DestroyWindow(hwnd);
728 return 0;
729 }
730 else
731 {
732 int ret;
733
734 ret = MessageBox(hwnd, MsgQuit, szAppName, MB_YESNO|MB_ICONQUESTION);
735 if (ret == IDYES)
736 {
737 WinHelp(hwnd, szHelpPath, HELP_QUIT, 0);
738 DestroyWindow(hwnd);
739 }
740 }
741 return 0;
742 }
743
744 return DefWindowProc (hwnd, iMsg, wParam, lParam);
745 }
746
747
748