e53efda79ce9a032632786ae79eba8930c302d28
11 TCHAR szHelpPath
[MAX_PATH
];
23 DWORD dwOptions
= OPTION_THREE_CARDS
;
27 typedef struct _CardBack
34 } CARDBACK
, *PCARDBACK
;
36 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
);
38 void MakePath(TCHAR
*szDest
, UINT nDestLen
, const TCHAR
*szExt
)
42 ptr
= szDest
+ GetModuleFileName(GetModuleHandle(0), szDest
, nDestLen
) - 1;
44 lstrcpy(ptr
+ 1, szExt
);
47 VOID
LoadSettings(VOID
)
54 if (RegCreateKeyEx(HKEY_CURRENT_USER
,
55 _T("Software\\ReactOS\\Solitaire"),
58 REG_OPTION_NON_VOLATILE
,
65 dwSize
= sizeof(DWORD
);
73 dwSize
= sizeof(DWORD
);
80 SolWnd
.SetBackCardIdx(dwBack
);
85 VOID
SaveSettings(VOID
)
91 if (RegCreateKeyEx(HKEY_CURRENT_USER
,
92 _T("Software\\ReactOS\\Solitaire"),
95 REG_OPTION_NON_VOLATILE
,
106 (CONST BYTE
*)&dwOptions
,
109 dwBack
= SolWnd
.GetBackCardIdx();
114 (CONST BYTE
*)&dwBack
,
123 int WINAPI
_tWinMain(HINSTANCE hInst
, HINSTANCE hPrev
, LPTSTR szCmdLine
, int iCmdShow
)
128 INITCOMMONCONTROLSEX ice
;
133 // Load application title
134 LoadString(hInst
, IDS_SOL_NAME
, szAppName
, sizeof(szAppName
) / sizeof(szAppName
[0]));
135 // Load MsgBox() texts here to avoid loading them many times later
136 LoadString(hInst
, IDS_SOL_ABOUT
, MsgAbout
, sizeof(MsgAbout
) / sizeof(MsgAbout
[0]));
137 LoadString(hInst
, IDS_SOL_QUIT
, MsgQuit
, sizeof(MsgQuit
) / sizeof(MsgQuit
[0]));
138 LoadString(hInst
, IDS_SOL_WIN
, MsgWin
, sizeof(MsgWin
) / sizeof(MsgWin
[0]));
139 LoadString(hInst
, IDS_SOL_DEAL
, MsgDeal
, sizeof(MsgDeal
) / sizeof(MsgDeal
[0]));
141 //Window class for the main application parent window
142 wndclass
.style
= 0;//CS_HREDRAW | CS_VREDRAW;
143 wndclass
.lpfnWndProc
= WndProc
;
144 wndclass
.cbClsExtra
= 0;
145 wndclass
.cbWndExtra
= 0;
146 wndclass
.hInstance
= hInst
;
147 wndclass
.hIcon
= LoadIcon (hInst
, MAKEINTRESOURCE(IDI_SOLITAIRE
));
148 wndclass
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
149 wndclass
.hbrBackground
= (HBRUSH
)NULL
;
150 wndclass
.lpszMenuName
= MAKEINTRESOURCE(IDR_MENU1
);
151 wndclass
.lpszClassName
= szAppName
;
153 RegisterClass(&wndclass
);
155 ice
.dwSize
= sizeof(ice
);
156 ice
.dwICC
= ICC_BAR_CLASSES
;
157 InitCommonControlsEx(&ice
);
159 srand((unsigned)GetTickCount());//timeGetTime());
165 //Construct the path to our help file
166 MakePath(szHelpPath
, MAX_PATH
, _T(".hlp"));
168 hwnd
= CreateWindow(szAppName
, // window class name
169 szAppName
, // window caption
171 ,//|WS_CLIPCHILDREN, // window style
172 CW_USEDEFAULT
, // initial x position
173 CW_USEDEFAULT
, // initial y position
174 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
175 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
176 NULL
, // parent window handle
177 NULL
, // use window class menu
178 hInst
, // program instance handle
179 NULL
); // creation parameters
183 ShowWindow(hwnd
, iCmdShow
);
186 hAccelTable
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDR_ACCELERATOR1
));
188 while(GetMessage(&msg
, NULL
,0,0))
190 if(!TranslateAccelerator(hwnd
, hAccelTable
, &msg
))
192 TranslateMessage(&msg
);
193 DispatchMessage(&msg
);
199 try { throw 0; } catch (int i
) { } /* HACK */
205 INT_PTR CALLBACK
OptionsDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
210 CheckRadioButton(hDlg
, IDC_OPT_DRAWONE
, IDC_OPT_DRAWTHREE
,
211 (dwOptions
& OPTION_THREE_CARDS
) ? IDC_OPT_DRAWTHREE
: IDC_OPT_DRAWONE
);
215 (dwOptions
& OPTION_SHOW_STATUS
) ? BST_CHECKED
: BST_UNCHECKED
);
219 switch(LOWORD(wParam
))
222 dwOptions
&= ~OPTION_THREE_CARDS
;
223 if (IsDlgButtonChecked(hDlg
, IDC_OPT_DRAWTHREE
) == BST_CHECKED
)
224 dwOptions
|= OPTION_THREE_CARDS
;
226 if (IsDlgButtonChecked(hDlg
, IDC_OPT_STATUSBAR
) == BST_CHECKED
)
227 dwOptions
|= OPTION_SHOW_STATUS
;
229 dwOptions
&= ~OPTION_SHOW_STATUS
;
231 EndDialog(hDlg
, TRUE
);
235 EndDialog(hDlg
, FALSE
);
243 VOID
ShowGameOptionsDlg(HWND hwnd
)
245 DWORD dwOldOptions
= dwOptions
;
246 RECT rcMain
, rcStatus
;
247 int nWidth
, nHeight
, nStatusHeight
;
249 if (DialogBox(hInstance
, MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsDlgProc
))
251 if ((dwOldOptions
& OPTION_THREE_CARDS
) != (dwOptions
& OPTION_THREE_CARDS
))
254 if ((dwOldOptions
& OPTION_SHOW_STATUS
) != (dwOptions
& OPTION_SHOW_STATUS
))
256 GetClientRect(hwndMain
, &rcMain
);
257 nHeight
= rcMain
.bottom
- rcMain
.top
;
258 nWidth
= rcMain
.right
- rcMain
.left
;
260 if (dwOptions
& OPTION_SHOW_STATUS
)
264 ShowWindow(hwndStatus
, SW_SHOW
);
265 GetWindowRect(hwndStatus
, &rcStatus
);
266 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
267 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
-nStatusHeight
, TRUE
);
268 MoveWindow(hwndStatus
, 0, nHeight
-nStatusHeight
, nWidth
, nHeight
, TRUE
);
270 // Force the window to process WM_GETMINMAXINFO again
271 GetWindowRect(hwndMain
, &rc
);
272 SetWindowPos(hwndMain
, NULL
, 0, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, SWP_NOMOVE
| SWP_NOZORDER
);
276 ShowWindow(hwndStatus
, SW_HIDE
);
277 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
285 CardImageWndProc(HWND hwnd
,
290 PCARDBACK pCardBack
= (PCARDBACK
)GetWindowLongPtr(hwnd
,
292 static WNDPROC hOldProc
= NULL
;
294 if (!hOldProc
&& pCardBack
)
295 hOldProc
= pCardBack
->hOldProc
;
304 HBRUSH hBrush
, hOldBrush
;
307 hdc
= BeginPaint(hwnd
, &ps
);
309 if (pCardBack
->bSelected
)
311 hPen
= CreatePen(PS_SOLID
, 2, RGB(0,0,0));
315 DWORD Face
= GetSysColor(COLOR_3DFACE
);
316 hPen
= CreatePen(PS_SOLID
, 2, Face
);
319 GetClientRect(hwnd
, &rc
);
320 hBrush
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
321 hOldPen
= (HPEN
)SelectObject(hdc
, hPen
);
322 hOldBrush
= (HBRUSH
)SelectObject(hdc
, hBrush
);
333 CARDBACK_OPTIONS_WIDTH
,
334 CARDBACK_OPTIONS_HEIGHT
,
336 pCardBack
->hdcNum
* __cardwidth
,
342 SelectObject(hdc
, hOldPen
);
343 SelectObject(hdc
, hOldBrush
);
351 pCardBack
->bSelected
= pCardBack
->bSelected
? FALSE
: TRUE
;
355 return CallWindowProc(hOldProc
,
363 INT_PTR CALLBACK
CardBackDlgProc(HWND hDlg
,
368 static PCARDBACK pCardBacks
= NULL
;
375 SIZE_T size
= sizeof(CARDBACK
) * NUM_CARDBACKS
;
377 pCardBacks
= (PCARDBACK
)HeapAlloc(GetProcessHeap(),
381 for (i
= 0, c
= CARDBACK_START
; c
<= CARDBACK_END
; i
++, c
++)
383 pCardBacks
[i
].hSelf
= GetDlgItem(hDlg
, c
);
384 pCardBacks
[i
].bSelected
= FALSE
;
385 pCardBacks
[i
].hdcNum
= CARDBACK_RES_START
+ i
;
386 pCardBacks
[i
].imgNum
= i
+ 1;
387 pCardBacks
[i
].hOldProc
= (WNDPROC
)SetWindowLongPtr(pCardBacks
[i
].hSelf
,
389 (LONG_PTR
)CardImageWndProc
);
391 SetWindowLongPtr(pCardBacks
[i
].hSelf
,
393 (LONG_PTR
)&pCardBacks
[i
]);
400 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
403 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
405 if (pCardBacks
[i
].bSelected
)
407 num
= pCardBacks
[i
].imgNum
;
411 EndDialog(hDlg
, LOWORD(wParam
) == IDOK
? num
: FALSE
);
412 HeapFree(GetProcessHeap(), 0, pCardBacks
);
416 if (HIWORD(wParam
) == STN_CLICKED
)
420 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
422 if (pCardBacks
[i
].hSelf
== (HWND
)lParam
)
424 pCardBacks
[i
].bSelected
= TRUE
;
427 pCardBacks
[i
].bSelected
= FALSE
;
429 GetClientRect(pCardBacks
[i
].hSelf
, &rc
);
430 InvalidateRect(pCardBacks
[i
].hSelf
, &rc
, TRUE
);
441 VOID
ShowDeckOptionsDlg(HWND hwnd
)
445 if ((cardBack
= DialogBox(hInstance
,
446 MAKEINTRESOURCE(IDD_CARDBACK
),
450 SolWnd
.SetBackCardIdx(CARDBACK_RES_START
+ (cardBack
- 1));
455 //-----------------------------------------------------------------------------
456 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
458 static int nWidth
, nHeight
, nStatusHeight
;
464 int parts
[] = { 100, -1 };
467 hwndStatus
= CreateStatusWindow(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, _T("Ready"), hwnd
, 0);
469 //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
471 SendMessage(hwndStatus
, SB_SETPARTS
, 2, (LPARAM
)parts
);
472 SendMessage(hwndStatus
, SB_SETTEXT
, 0 | SBT_NOBORDERS
, (LPARAM
)"");
474 SolWnd
.Create(hwnd
, WS_EX_CLIENTEDGE
, WS_CHILD
|WS_VISIBLE
, 0, 0, 0, 0);
478 // The status bar height is fixed and needed later in WM_SIZE and WM_GETMINMAXINFO
479 // Force the window to process WM_GETMINMAXINFO again
480 GetWindowRect(hwndStatus
, &rcStatus
);
481 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
483 // Hide status bar if options say so
484 if (!(dwOptions
& OPTION_SHOW_STATUS
))
486 ShowWindow(hwndStatus
, SW_HIDE
);
489 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOZORDER
);
493 dwAppStartTime
= GetTickCount();
503 nWidth
= LOWORD(lParam
);
504 nHeight
= HIWORD(lParam
);
506 if (dwOptions
& OPTION_SHOW_STATUS
)
508 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
- nStatusHeight
, TRUE
);
509 MoveWindow(hwndStatus
, 0, nHeight
- nStatusHeight
, nWidth
, nStatusHeight
, TRUE
);
513 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
515 //parts[0] = nWidth - 256;
516 //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
519 case WM_GETMINMAXINFO
:
523 mmi
= (MINMAXINFO
*)lParam
;
524 mmi
->ptMinTrackSize
.x
= X_BORDER
+ NUM_ROW_STACKS
* (__cardwidth
+ X_ROWSTACK_BORDER
) + X_BORDER
;
525 mmi
->ptMinTrackSize
.y
= GetSystemMetrics(SM_CYCAPTION
) +
526 GetSystemMetrics(SM_CYMENU
) +
530 6 * yRowStackCardOffset
+
533 (dwOptions
& OPTION_SHOW_STATUS
? nStatusHeight
: 0);
538 switch(LOWORD(wParam
))
541 //simulate a button click on the new button..
546 ShowDeckOptionsDlg(hwnd
);
549 case IDM_GAME_OPTIONS
:
550 ShowGameOptionsDlg(hwnd
);
553 case IDM_HELP_CONTENTS
:
554 WinHelp(hwnd
, szHelpPath
, HELP_CONTENTS
, 0);//HELP_KEY, (DWORD)"How to play");
558 MessageBox(hwnd
, MsgAbout
, szAppName
, MB_OK
|MB_ICONINFORMATION
);
562 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
569 if (fGameStarted
== false)
578 ret
= MessageBox(hwnd
, MsgQuit
, szAppName
, MB_OKCANCEL
|MB_ICONQUESTION
);
581 WinHelp(hwnd
, szHelpPath
, HELP_QUIT
, 0);
588 return DefWindowProc (hwnd
, iMsg
, wParam
, lParam
);