7 #include "cardlib/cardlib.h"
11 TCHAR szHelpPath
[MAX_PATH
];
26 typedef struct _CardBack
33 } CARDBACK
, *PCARDBACK
;
35 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
);
37 void MakePath(TCHAR
*szDest
, UINT nDestLen
, const TCHAR
*szExt
)
41 ptr
= szDest
+ GetModuleFileName(GetModuleHandle(0), szDest
, nDestLen
) - 1;
43 lstrcpy(ptr
+ 1, szExt
);
46 VOID
LoadSettings(VOID
)
53 if (RegCreateKeyEx(HKEY_CURRENT_USER
,
54 _T("Software\\ReactOS\\Solitaire"),
57 REG_OPTION_NON_VOLATILE
,
64 dwSize
= sizeof(DWORD
);
72 dwSize
= sizeof(DWORD
);
79 SolWnd
.SetBackCardIdx(dwBack
);
84 VOID
SaveSettings(VOID
)
90 if (RegCreateKeyEx(HKEY_CURRENT_USER
,
91 _T("Software\\ReactOS\\Solitaire"),
94 REG_OPTION_NON_VOLATILE
,
105 (CONST BYTE
*)&dwOptions
,
108 dwBack
= SolWnd
.GetBackCardIdx();
113 (CONST BYTE
*)&dwBack
,
122 int WINAPI
_tWinMain(HINSTANCE hInst
, HINSTANCE hPrev
, LPTSTR szCmdLine
, int iCmdShow
)
127 INITCOMMONCONTROLSEX ice
;
132 // Load application title
133 LoadString(hInst
, IDS_SOL_NAME
, szAppName
, sizeof(szAppName
) / sizeof(szAppName
[0]));
134 // Load MsgBox() texts here to avoid loading them many times later
135 LoadString(hInst
, IDS_SOL_ABOUT
, MsgAbout
, sizeof(MsgAbout
) / sizeof(MsgAbout
[0]));
136 LoadString(hInst
, IDS_SOL_QUIT
, MsgQuit
, sizeof(MsgQuit
) / sizeof(MsgQuit
[0]));
137 LoadString(hInst
, IDS_SOL_WIN
, MsgWin
, sizeof(MsgWin
) / sizeof(MsgWin
[0]));
139 //Window class for the main application parent window
140 wndclass
.style
= 0;//CS_HREDRAW | CS_VREDRAW;
141 wndclass
.lpfnWndProc
= WndProc
;
142 wndclass
.cbClsExtra
= 0;
143 wndclass
.cbWndExtra
= 0;
144 wndclass
.hInstance
= hInst
;
145 wndclass
.hIcon
= LoadIcon (hInst
, MAKEINTRESOURCE(IDI_SOLITAIRE
));
146 wndclass
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
147 wndclass
.hbrBackground
= (HBRUSH
)NULL
;
148 wndclass
.lpszMenuName
= MAKEINTRESOURCE(IDR_MENU1
);
149 wndclass
.lpszClassName
= szAppName
;
151 RegisterClass(&wndclass
);
153 ice
.dwSize
= sizeof(ice
);
154 ice
.dwICC
= ICC_BAR_CLASSES
;
155 InitCommonControlsEx(&ice
);
157 srand((unsigned)GetTickCount());//timeGetTime());
163 //Construct the path to our help file
164 MakePath(szHelpPath
, MAX_PATH
, _T(".hlp"));
166 hwnd
= CreateWindow(szAppName
, // window class name
167 szAppName
, // window caption
169 ,//|WS_CLIPCHILDREN, // window style
170 CW_USEDEFAULT
, // initial x position
171 CW_USEDEFAULT
, // initial y position
172 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
173 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
174 NULL
, // parent window handle
175 NULL
, // use window class menu
176 hInst
, // program instance handle
177 NULL
); // creation parameters
181 ShowWindow(hwnd
, iCmdShow
);
184 hAccelTable
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDR_ACCELERATOR1
));
186 while(GetMessage(&msg
, NULL
,0,0))
188 if(!TranslateAccelerator(hwnd
, hAccelTable
, &msg
))
190 TranslateMessage(&msg
);
191 DispatchMessage(&msg
);
201 BOOL CALLBACK
OptionsDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
206 CheckRadioButton(hDlg
, IDC_OPT_DRAWONE
, IDC_OPT_DRAWTHREE
,
207 (dwOptions
& OPTION_THREE_CARDS
) ? IDC_OPT_DRAWTHREE
: IDC_OPT_DRAWONE
);
211 (dwOptions
& OPTION_SHOW_STATUS
) ? BST_CHECKED
: BST_UNCHECKED
);
215 switch(LOWORD(wParam
))
218 dwOptions
&= ~OPTION_THREE_CARDS
;
219 if (IsDlgButtonChecked(hDlg
, IDC_OPT_DRAWTHREE
) == BST_CHECKED
)
220 dwOptions
|= OPTION_THREE_CARDS
;
222 if (IsDlgButtonChecked(hDlg
, IDC_OPT_STATUSBAR
) == BST_CHECKED
)
223 dwOptions
|= OPTION_SHOW_STATUS
;
225 dwOptions
&= ~OPTION_SHOW_STATUS
;
227 EndDialog(hDlg
, TRUE
);
231 EndDialog(hDlg
, FALSE
);
239 VOID
ShowGameOptionsDlg(HWND hwnd
)
241 DWORD dwOldOptions
= dwOptions
;
242 RECT rcMain
, rcStatus
;
243 int nWidth
, nHeight
, nStatusHeight
;
245 if (DialogBox(hInstance
, MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsDlgProc
))
247 if ((dwOldOptions
& OPTION_THREE_CARDS
) != (dwOptions
& OPTION_THREE_CARDS
))
250 if ((dwOldOptions
& OPTION_SHOW_STATUS
) != (dwOptions
& OPTION_SHOW_STATUS
))
252 GetClientRect(hwndMain
, &rcMain
);
253 nHeight
= rcMain
.bottom
- rcMain
.top
;
254 nWidth
= rcMain
.right
- rcMain
.left
;
256 if (dwOptions
& OPTION_SHOW_STATUS
)
260 ShowWindow(hwndStatus
, SW_SHOW
);
261 GetWindowRect(hwndStatus
, &rcStatus
);
262 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
263 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
-nStatusHeight
, TRUE
);
264 MoveWindow(hwndStatus
, 0, nHeight
-nStatusHeight
, nWidth
, nHeight
, TRUE
);
266 // Force the window to process WM_GETMINMAXINFO again
267 GetWindowRect(hwndMain
, &rc
);
268 SetWindowPos(hwndMain
, NULL
, 0, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, SWP_NOMOVE
| SWP_NOZORDER
);
272 ShowWindow(hwndStatus
, SW_HIDE
);
273 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
281 CardImageWndProc(HWND hwnd
,
286 PCARDBACK pCardBack
= (PCARDBACK
)GetWindowLongPtr(hwnd
,
288 static WNDPROC hOldProc
= NULL
;
290 if (!hOldProc
&& pCardBack
)
291 hOldProc
= pCardBack
->hOldProc
;
300 HBRUSH hBrush
, hOldBrush
;
303 hdc
= BeginPaint(hwnd
, &ps
);
305 if (pCardBack
->bSelected
)
307 hPen
= CreatePen(PS_SOLID
, 2, RGB(0,0,0));
311 DWORD Face
= GetSysColor(COLOR_3DFACE
);
312 hPen
= CreatePen(PS_SOLID
, 2, Face
);
315 GetClientRect(hwnd
, &rc
);
316 hBrush
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
317 hOldPen
= (HPEN
)SelectObject(hdc
, hPen
);
318 hOldBrush
= (HBRUSH
)SelectObject(hdc
, hBrush
);
329 CARDBACK_OPTIONS_WIDTH
,
330 CARDBACK_OPTIONS_HEIGHT
,
332 pCardBack
->hdcNum
* __cardwidth
,
338 SelectObject(hdc
, hOldPen
);
339 SelectObject(hdc
, hOldBrush
);
347 pCardBack
->bSelected
= pCardBack
->bSelected
? FALSE
: TRUE
;
351 return CallWindowProc(hOldProc
,
359 BOOL CALLBACK
CardBackDlgProc(HWND hDlg
,
364 static PCARDBACK pCardBacks
= NULL
;
371 SIZE_T size
= sizeof(CARDBACK
) * NUM_CARDBACKS
;
373 pCardBacks
= (PCARDBACK
)HeapAlloc(GetProcessHeap(),
377 for (i
= 0, c
= CARDBACK_START
; c
<= CARDBACK_END
; i
++, c
++)
379 pCardBacks
[i
].hSelf
= GetDlgItem(hDlg
, c
);
380 pCardBacks
[i
].bSelected
= FALSE
;
381 pCardBacks
[i
].hdcNum
= CARDBACK_RES_START
+ i
;
382 pCardBacks
[i
].imgNum
= i
+ 1;
383 pCardBacks
[i
].hOldProc
= (WNDPROC
)SetWindowLongPtr(pCardBacks
[i
].hSelf
,
385 (LONG_PTR
)CardImageWndProc
);
387 SetWindowLongPtr(pCardBacks
[i
].hSelf
,
389 (LONG_PTR
)&pCardBacks
[i
]);
396 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
399 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
401 if (pCardBacks
[i
].bSelected
)
403 num
= pCardBacks
[i
].imgNum
;
407 EndDialog(hDlg
, LOWORD(wParam
) == IDOK
? num
: FALSE
);
408 HeapFree(GetProcessHeap(), 0, pCardBacks
);
412 if (HIWORD(wParam
) == STN_CLICKED
)
416 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
418 if (pCardBacks
[i
].hSelf
== (HWND
)lParam
)
420 pCardBacks
[i
].bSelected
= TRUE
;
423 pCardBacks
[i
].bSelected
= FALSE
;
425 GetClientRect(pCardBacks
[i
].hSelf
, &rc
);
426 InvalidateRect(pCardBacks
[i
].hSelf
, &rc
, TRUE
);
437 VOID
ShowDeckOptionsDlg(HWND hwnd
)
441 if ((cardBack
= DialogBox(hInstance
,
442 MAKEINTRESOURCE(IDD_CARDBACK
),
446 SolWnd
.SetBackCardIdx(CARDBACK_RES_START
+ (cardBack
- 1));
451 //-----------------------------------------------------------------------------
452 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
454 static int nWidth
, nHeight
, nStatusHeight
;
460 int parts
[] = { 100, -1 };
463 hwndStatus
= CreateStatusWindow(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, _T("Ready"), hwnd
, 0);
465 //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
467 SendMessage(hwndStatus
, SB_SETPARTS
, 2, (LPARAM
)parts
);
468 SendMessage(hwndStatus
, SB_SETTEXT
, 0 | SBT_NOBORDERS
, (LPARAM
)"");
470 SolWnd
.Create(hwnd
, WS_EX_CLIENTEDGE
, WS_CHILD
|WS_VISIBLE
, 0, 0, 0, 0);
474 // The status bar height is fixed and needed later in WM_SIZE and WM_GETMINMAXINFO
475 // Force the window to process WM_GETMINMAXINFO again
476 GetWindowRect(hwndStatus
, &rcStatus
);
477 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
478 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOZORDER
);
482 dwAppStartTime
= GetTickCount();
492 nWidth
= LOWORD(lParam
);
493 nHeight
= HIWORD(lParam
);
495 if (dwOptions
& OPTION_SHOW_STATUS
)
497 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
- nStatusHeight
, TRUE
);
498 MoveWindow(hwndStatus
, 0, nHeight
- nStatusHeight
, nWidth
, nHeight
, TRUE
);
499 SendMessage(hwndStatus
, WM_SIZE
, wParam
, lParam
);
503 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
505 //parts[0] = nWidth - 256;
506 //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
509 case WM_GETMINMAXINFO
:
513 mmi
= (MINMAXINFO
*)lParam
;
514 mmi
->ptMinTrackSize
.x
= X_BORDER
+ NUM_ROW_STACKS
* (__cardwidth
+ X_ROWSTACK_BORDER
) + X_BORDER
;
515 mmi
->ptMinTrackSize
.y
= GetSystemMetrics(SM_CYCAPTION
) +
516 GetSystemMetrics(SM_CYMENU
) +
520 6 * yRowStackCardOffset
+
523 (dwOptions
& OPTION_SHOW_STATUS
? nStatusHeight
: 0);
528 switch(LOWORD(wParam
))
531 //simulate a button click on the new button..
536 ShowDeckOptionsDlg(hwnd
);
539 case IDM_GAME_OPTIONS
:
540 ShowGameOptionsDlg(hwnd
);
543 case IDM_HELP_CONTENTS
:
544 WinHelp(hwnd
, szHelpPath
, HELP_CONTENTS
, 0);//HELP_KEY, (DWORD)"How to play");
548 MessageBox(hwnd
, MsgAbout
, szAppName
, MB_OK
|MB_ICONINFORMATION
);
552 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
559 if (fGameStarted
== false)
568 ret
= MessageBox(hwnd
, MsgQuit
, szAppName
, MB_OKCANCEL
|MB_ICONQUESTION
);
571 WinHelp(hwnd
, szHelpPath
, HELP_QUIT
, 0);
578 return DefWindowProc (hwnd
, iMsg
, wParam
, lParam
);