9 TCHAR szHelpPath
[MAX_PATH
];
21 DWORD dwOptions
= OPTION_THREE_CARDS
;
25 typedef struct _CardBack
32 } CARDBACK
, *PCARDBACK
;
34 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
);
36 void MakePath(TCHAR
*szDest
, UINT nDestLen
, const TCHAR
*szExt
)
40 ptr
= szDest
+ GetModuleFileName(GetModuleHandle(0), szDest
, nDestLen
) - 1;
42 lstrcpy(ptr
+ 1, szExt
);
45 VOID
LoadSettings(VOID
)
52 if (RegCreateKeyEx(HKEY_CURRENT_USER
,
53 _T("Software\\ReactOS\\Solitaire"),
56 REG_OPTION_NON_VOLATILE
,
63 dwSize
= sizeof(DWORD
);
71 dwSize
= sizeof(DWORD
);
78 SolWnd
.SetBackCardIdx(dwBack
);
83 VOID
SaveSettings(VOID
)
89 if (RegCreateKeyEx(HKEY_CURRENT_USER
,
90 _T("Software\\ReactOS\\Solitaire"),
93 REG_OPTION_NON_VOLATILE
,
104 (CONST BYTE
*)&dwOptions
,
107 dwBack
= SolWnd
.GetBackCardIdx();
112 (CONST BYTE
*)&dwBack
,
121 int WINAPI
_tWinMain(HINSTANCE hInst
, HINSTANCE hPrev
, LPTSTR szCmdLine
, int iCmdShow
)
126 INITCOMMONCONTROLSEX ice
;
131 // Load application title
132 LoadString(hInst
, IDS_SOL_NAME
, szAppName
, sizeof(szAppName
) / sizeof(szAppName
[0]));
133 // Load MsgBox() texts here to avoid loading them many times later
134 LoadString(hInst
, IDS_SOL_ABOUT
, MsgAbout
, sizeof(MsgAbout
) / sizeof(MsgAbout
[0]));
135 LoadString(hInst
, IDS_SOL_QUIT
, MsgQuit
, sizeof(MsgQuit
) / sizeof(MsgQuit
[0]));
136 LoadString(hInst
, IDS_SOL_WIN
, MsgWin
, sizeof(MsgWin
) / sizeof(MsgWin
[0]));
137 LoadString(hInst
, IDS_SOL_DEAL
, MsgDeal
, sizeof(MsgDeal
) / sizeof(MsgDeal
[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 INT_PTR 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
;
244 if (DialogBox(hInstance
, MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsDlgProc
))
246 if ((dwOldOptions
& OPTION_THREE_CARDS
) != (dwOptions
& OPTION_THREE_CARDS
))
249 if ((dwOldOptions
& OPTION_SHOW_STATUS
) != (dwOptions
& OPTION_SHOW_STATUS
))
251 int nWidth
, nHeight
, nStatusHeight
;
253 GetClientRect(hwndMain
, &rcMain
);
254 nHeight
= rcMain
.bottom
- rcMain
.top
;
255 nWidth
= rcMain
.right
- rcMain
.left
;
257 if (dwOptions
& OPTION_SHOW_STATUS
)
261 ShowWindow(hwndStatus
, SW_SHOW
);
262 GetWindowRect(hwndStatus
, &rcStatus
);
263 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
264 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
-nStatusHeight
, TRUE
);
265 MoveWindow(hwndStatus
, 0, nHeight
-nStatusHeight
, nWidth
, nHeight
, TRUE
);
267 // Force the window to process WM_GETMINMAXINFO again
268 GetWindowRect(hwndMain
, &rc
);
269 SetWindowPos(hwndMain
, NULL
, 0, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, SWP_NOMOVE
| SWP_NOZORDER
);
273 ShowWindow(hwndStatus
, SW_HIDE
);
274 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
282 CardImageWndProc(HWND hwnd
,
287 PCARDBACK pCardBack
= (PCARDBACK
)GetWindowLongPtr(hwnd
,
289 static WNDPROC hOldProc
= NULL
;
291 if (!hOldProc
&& pCardBack
)
292 hOldProc
= pCardBack
->hOldProc
;
301 HBRUSH hBrush
, hOldBrush
;
304 hdc
= BeginPaint(hwnd
, &ps
);
306 if (pCardBack
->bSelected
)
308 hPen
= CreatePen(PS_SOLID
, 2, RGB(0,0,0));
312 DWORD Face
= GetSysColor(COLOR_3DFACE
);
313 hPen
= CreatePen(PS_SOLID
, 2, Face
);
316 GetClientRect(hwnd
, &rc
);
317 hBrush
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
318 hOldPen
= (HPEN
)SelectObject(hdc
, hPen
);
319 hOldBrush
= (HBRUSH
)SelectObject(hdc
, hBrush
);
330 CARDBACK_OPTIONS_WIDTH
,
331 CARDBACK_OPTIONS_HEIGHT
,
333 pCardBack
->hdcNum
* __cardwidth
,
339 SelectObject(hdc
, hOldPen
);
340 SelectObject(hdc
, hOldBrush
);
348 pCardBack
->bSelected
= pCardBack
->bSelected
? FALSE
: TRUE
;
352 return CallWindowProc(hOldProc
,
360 INT_PTR CALLBACK
CardBackDlgProc(HWND hDlg
,
365 static PCARDBACK pCardBacks
= NULL
;
372 SIZE_T size
= sizeof(CARDBACK
) * NUM_CARDBACKS
;
374 pCardBacks
= (PCARDBACK
)HeapAlloc(GetProcessHeap(),
378 for (i
= 0, c
= CARDBACK_START
; c
<= CARDBACK_END
; i
++, c
++)
380 pCardBacks
[i
].hSelf
= GetDlgItem(hDlg
, c
);
381 pCardBacks
[i
].bSelected
= FALSE
;
382 pCardBacks
[i
].hdcNum
= CARDBACK_RES_START
+ i
;
383 pCardBacks
[i
].imgNum
= i
+ 1;
384 pCardBacks
[i
].hOldProc
= (WNDPROC
)SetWindowLongPtr(pCardBacks
[i
].hSelf
,
386 (LONG_PTR
)CardImageWndProc
);
388 SetWindowLongPtr(pCardBacks
[i
].hSelf
,
390 (LONG_PTR
)&pCardBacks
[i
]);
397 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
400 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
402 if (pCardBacks
[i
].bSelected
)
404 num
= pCardBacks
[i
].imgNum
;
408 EndDialog(hDlg
, LOWORD(wParam
) == IDOK
? num
: FALSE
);
409 HeapFree(GetProcessHeap(), 0, pCardBacks
);
413 if (HIWORD(wParam
) == STN_CLICKED
)
417 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
419 if (pCardBacks
[i
].hSelf
== (HWND
)lParam
)
421 pCardBacks
[i
].bSelected
= TRUE
;
424 pCardBacks
[i
].bSelected
= FALSE
;
426 GetClientRect(pCardBacks
[i
].hSelf
, &rc
);
427 InvalidateRect(pCardBacks
[i
].hSelf
, &rc
, TRUE
);
438 VOID
ShowDeckOptionsDlg(HWND hwnd
)
442 if ((cardBack
= DialogBox(hInstance
,
443 MAKEINTRESOURCE(IDD_CARDBACK
),
447 SolWnd
.SetBackCardIdx(CARDBACK_RES_START
+ (cardBack
- 1));
452 //-----------------------------------------------------------------------------
453 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
455 static int nWidth
, nHeight
, nStatusHeight
;
461 int parts
[] = { 100, -1 };
464 hwndStatus
= CreateStatusWindow(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, _T("Ready"), hwnd
, 0);
466 //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
468 SendMessage(hwndStatus
, SB_SETPARTS
, 2, (LPARAM
)parts
);
469 SendMessage(hwndStatus
, SB_SETTEXT
, 0 | SBT_NOBORDERS
, (LPARAM
)"");
471 SolWnd
.Create(hwnd
, WS_EX_CLIENTEDGE
, WS_CHILD
|WS_VISIBLE
, 0, 0, 0, 0);
475 // The status bar height is fixed and needed later in WM_SIZE and WM_GETMINMAXINFO
476 // Force the window to process WM_GETMINMAXINFO again
477 GetWindowRect(hwndStatus
, &rcStatus
);
478 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
480 // Hide status bar if options say so
481 if (!(dwOptions
& OPTION_SHOW_STATUS
))
483 ShowWindow(hwndStatus
, SW_HIDE
);
486 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOZORDER
);
490 dwAppStartTime
= GetTickCount();
500 nWidth
= LOWORD(lParam
);
501 nHeight
= HIWORD(lParam
);
503 if (dwOptions
& OPTION_SHOW_STATUS
)
505 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
- nStatusHeight
, TRUE
);
506 MoveWindow(hwndStatus
, 0, nHeight
- nStatusHeight
, nWidth
, nStatusHeight
, TRUE
);
510 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
512 //parts[0] = nWidth - 256;
513 //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
516 case WM_GETMINMAXINFO
:
520 mmi
= (MINMAXINFO
*)lParam
;
521 mmi
->ptMinTrackSize
.x
= X_BORDER
+ NUM_ROW_STACKS
* (__cardwidth
+ X_ROWSTACK_BORDER
) + X_BORDER
;
522 mmi
->ptMinTrackSize
.y
= GetSystemMetrics(SM_CYCAPTION
) +
523 GetSystemMetrics(SM_CYMENU
) +
527 6 * yRowStackCardOffset
+
530 (dwOptions
& OPTION_SHOW_STATUS
? nStatusHeight
: 0);
535 switch(LOWORD(wParam
))
538 //simulate a button click on the new button..
543 ShowDeckOptionsDlg(hwnd
);
546 case IDM_GAME_OPTIONS
:
547 ShowGameOptionsDlg(hwnd
);
550 case IDM_HELP_CONTENTS
:
551 WinHelp(hwnd
, szHelpPath
, HELP_CONTENTS
, 0);//HELP_KEY, (DWORD)"How to play");
555 MessageBox(hwnd
, MsgAbout
, szAppName
, MB_OK
|MB_ICONINFORMATION
);
559 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
566 if (fGameStarted
== false)
575 ret
= MessageBox(hwnd
, MsgQuit
, szAppName
, MB_YESNO
|MB_ICONQUESTION
);
578 WinHelp(hwnd
, szHelpPath
, HELP_QUIT
, 0);
585 return DefWindowProc (hwnd
, iMsg
, wParam
, lParam
);