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
);
203 INT_PTR CALLBACK
OptionsDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
208 CheckRadioButton(hDlg
, IDC_OPT_DRAWONE
, IDC_OPT_DRAWTHREE
,
209 (dwOptions
& OPTION_THREE_CARDS
) ? IDC_OPT_DRAWTHREE
: IDC_OPT_DRAWONE
);
213 (dwOptions
& OPTION_SHOW_STATUS
) ? BST_CHECKED
: BST_UNCHECKED
);
217 switch(LOWORD(wParam
))
220 dwOptions
&= ~OPTION_THREE_CARDS
;
221 if (IsDlgButtonChecked(hDlg
, IDC_OPT_DRAWTHREE
) == BST_CHECKED
)
222 dwOptions
|= OPTION_THREE_CARDS
;
224 if (IsDlgButtonChecked(hDlg
, IDC_OPT_STATUSBAR
) == BST_CHECKED
)
225 dwOptions
|= OPTION_SHOW_STATUS
;
227 dwOptions
&= ~OPTION_SHOW_STATUS
;
229 EndDialog(hDlg
, TRUE
);
233 EndDialog(hDlg
, FALSE
);
241 VOID
ShowGameOptionsDlg(HWND hwnd
)
243 DWORD dwOldOptions
= dwOptions
;
244 RECT rcMain
, rcStatus
;
245 int nWidth
, nHeight
, nStatusHeight
;
247 if (DialogBox(hInstance
, MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsDlgProc
))
249 if ((dwOldOptions
& OPTION_THREE_CARDS
) != (dwOptions
& OPTION_THREE_CARDS
))
252 if ((dwOldOptions
& OPTION_SHOW_STATUS
) != (dwOptions
& OPTION_SHOW_STATUS
))
254 GetClientRect(hwndMain
, &rcMain
);
255 nHeight
= rcMain
.bottom
- rcMain
.top
;
256 nWidth
= rcMain
.right
- rcMain
.left
;
258 if (dwOptions
& OPTION_SHOW_STATUS
)
262 ShowWindow(hwndStatus
, SW_SHOW
);
263 GetWindowRect(hwndStatus
, &rcStatus
);
264 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
265 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
-nStatusHeight
, TRUE
);
266 MoveWindow(hwndStatus
, 0, nHeight
-nStatusHeight
, nWidth
, nHeight
, TRUE
);
268 // Force the window to process WM_GETMINMAXINFO again
269 GetWindowRect(hwndMain
, &rc
);
270 SetWindowPos(hwndMain
, NULL
, 0, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, SWP_NOMOVE
| SWP_NOZORDER
);
274 ShowWindow(hwndStatus
, SW_HIDE
);
275 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
283 CardImageWndProc(HWND hwnd
,
288 PCARDBACK pCardBack
= (PCARDBACK
)GetWindowLongPtr(hwnd
,
290 static WNDPROC hOldProc
= NULL
;
292 if (!hOldProc
&& pCardBack
)
293 hOldProc
= pCardBack
->hOldProc
;
302 HBRUSH hBrush
, hOldBrush
;
305 hdc
= BeginPaint(hwnd
, &ps
);
307 if (pCardBack
->bSelected
)
309 hPen
= CreatePen(PS_SOLID
, 2, RGB(0,0,0));
313 DWORD Face
= GetSysColor(COLOR_3DFACE
);
314 hPen
= CreatePen(PS_SOLID
, 2, Face
);
317 GetClientRect(hwnd
, &rc
);
318 hBrush
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
319 hOldPen
= (HPEN
)SelectObject(hdc
, hPen
);
320 hOldBrush
= (HBRUSH
)SelectObject(hdc
, hBrush
);
331 CARDBACK_OPTIONS_WIDTH
,
332 CARDBACK_OPTIONS_HEIGHT
,
334 pCardBack
->hdcNum
* __cardwidth
,
340 SelectObject(hdc
, hOldPen
);
341 SelectObject(hdc
, hOldBrush
);
349 pCardBack
->bSelected
= pCardBack
->bSelected
? FALSE
: TRUE
;
353 return CallWindowProc(hOldProc
,
361 INT_PTR CALLBACK
CardBackDlgProc(HWND hDlg
,
366 static PCARDBACK pCardBacks
= NULL
;
373 SIZE_T size
= sizeof(CARDBACK
) * NUM_CARDBACKS
;
375 pCardBacks
= (PCARDBACK
)HeapAlloc(GetProcessHeap(),
379 for (i
= 0, c
= CARDBACK_START
; c
<= CARDBACK_END
; i
++, c
++)
381 pCardBacks
[i
].hSelf
= GetDlgItem(hDlg
, c
);
382 pCardBacks
[i
].bSelected
= FALSE
;
383 pCardBacks
[i
].hdcNum
= CARDBACK_RES_START
+ i
;
384 pCardBacks
[i
].imgNum
= i
+ 1;
385 pCardBacks
[i
].hOldProc
= (WNDPROC
)SetWindowLongPtr(pCardBacks
[i
].hSelf
,
387 (LONG_PTR
)CardImageWndProc
);
389 SetWindowLongPtr(pCardBacks
[i
].hSelf
,
391 (LONG_PTR
)&pCardBacks
[i
]);
398 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
401 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
403 if (pCardBacks
[i
].bSelected
)
405 num
= pCardBacks
[i
].imgNum
;
409 EndDialog(hDlg
, LOWORD(wParam
) == IDOK
? num
: FALSE
);
410 HeapFree(GetProcessHeap(), 0, pCardBacks
);
414 if (HIWORD(wParam
) == STN_CLICKED
)
418 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
420 if (pCardBacks
[i
].hSelf
== (HWND
)lParam
)
422 pCardBacks
[i
].bSelected
= TRUE
;
425 pCardBacks
[i
].bSelected
= FALSE
;
427 GetClientRect(pCardBacks
[i
].hSelf
, &rc
);
428 InvalidateRect(pCardBacks
[i
].hSelf
, &rc
, TRUE
);
439 VOID
ShowDeckOptionsDlg(HWND hwnd
)
443 if ((cardBack
= DialogBox(hInstance
,
444 MAKEINTRESOURCE(IDD_CARDBACK
),
448 SolWnd
.SetBackCardIdx(CARDBACK_RES_START
+ (cardBack
- 1));
453 //-----------------------------------------------------------------------------
454 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
456 static int nWidth
, nHeight
, nStatusHeight
;
462 int parts
[] = { 100, -1 };
465 hwndStatus
= CreateStatusWindow(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, _T("Ready"), hwnd
, 0);
467 //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
469 SendMessage(hwndStatus
, SB_SETPARTS
, 2, (LPARAM
)parts
);
470 SendMessage(hwndStatus
, SB_SETTEXT
, 0 | SBT_NOBORDERS
, (LPARAM
)"");
472 SolWnd
.Create(hwnd
, WS_EX_CLIENTEDGE
, WS_CHILD
|WS_VISIBLE
, 0, 0, 0, 0);
476 // The status bar height is fixed and needed later in WM_SIZE and WM_GETMINMAXINFO
477 // Force the window to process WM_GETMINMAXINFO again
478 GetWindowRect(hwndStatus
, &rcStatus
);
479 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
481 // Hide status bar if options say so
482 if (!(dwOptions
& OPTION_SHOW_STATUS
))
484 ShowWindow(hwndStatus
, SW_HIDE
);
487 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOZORDER
);
491 dwAppStartTime
= GetTickCount();
501 nWidth
= LOWORD(lParam
);
502 nHeight
= HIWORD(lParam
);
504 if (dwOptions
& OPTION_SHOW_STATUS
)
506 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
- nStatusHeight
, TRUE
);
507 MoveWindow(hwndStatus
, 0, nHeight
- nStatusHeight
, nWidth
, nStatusHeight
, TRUE
);
511 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
513 //parts[0] = nWidth - 256;
514 //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
517 case WM_GETMINMAXINFO
:
521 mmi
= (MINMAXINFO
*)lParam
;
522 mmi
->ptMinTrackSize
.x
= X_BORDER
+ NUM_ROW_STACKS
* (__cardwidth
+ X_ROWSTACK_BORDER
) + X_BORDER
;
523 mmi
->ptMinTrackSize
.y
= GetSystemMetrics(SM_CYCAPTION
) +
524 GetSystemMetrics(SM_CYMENU
) +
528 6 * yRowStackCardOffset
+
531 (dwOptions
& OPTION_SHOW_STATUS
? nStatusHeight
: 0);
536 switch(LOWORD(wParam
))
539 //simulate a button click on the new button..
544 ShowDeckOptionsDlg(hwnd
);
547 case IDM_GAME_OPTIONS
:
548 ShowGameOptionsDlg(hwnd
);
551 case IDM_HELP_CONTENTS
:
552 WinHelp(hwnd
, szHelpPath
, HELP_CONTENTS
, 0);//HELP_KEY, (DWORD)"How to play");
556 MessageBox(hwnd
, MsgAbout
, szAppName
, MB_OK
|MB_ICONINFORMATION
);
560 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
567 if (fGameStarted
== false)
576 ret
= MessageBox(hwnd
, MsgQuit
, szAppName
, MB_OKCANCEL
|MB_ICONQUESTION
);
579 WinHelp(hwnd
, szHelpPath
, HELP_QUIT
, 0);
586 return DefWindowProc (hwnd
, iMsg
, wParam
, lParam
);