4 TCHAR szHelpPath
[MAX_PATH
];
16 DWORD dwOptions
= OPTION_THREE_CARDS
;
20 typedef struct _CardBack
27 } CARDBACK
, *PCARDBACK
;
29 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
);
31 void MakePath(TCHAR
*szDest
, UINT nDestLen
, const TCHAR
*szExt
)
35 ptr
= szDest
+ GetModuleFileName(GetModuleHandle(0), szDest
, nDestLen
) - 1;
37 lstrcpy(ptr
+ 1, szExt
);
40 VOID
LoadSettings(VOID
)
47 if (RegCreateKeyEx(HKEY_CURRENT_USER
,
48 _T("Software\\ReactOS\\Solitaire"),
51 REG_OPTION_NON_VOLATILE
,
58 dwSize
= sizeof(DWORD
);
66 dwSize
= sizeof(DWORD
);
73 SolWnd
.SetBackCardIdx(dwBack
);
78 VOID
SaveSettings(VOID
)
84 if (RegCreateKeyEx(HKEY_CURRENT_USER
,
85 _T("Software\\ReactOS\\Solitaire"),
88 REG_OPTION_NON_VOLATILE
,
99 (CONST BYTE
*)&dwOptions
,
102 dwBack
= SolWnd
.GetBackCardIdx();
107 (CONST BYTE
*)&dwBack
,
116 int WINAPI
_tWinMain(HINSTANCE hInst
, HINSTANCE hPrev
, LPTSTR szCmdLine
, int iCmdShow
)
121 INITCOMMONCONTROLSEX ice
;
126 // Load application title
127 LoadString(hInst
, IDS_SOL_NAME
, szAppName
, sizeof(szAppName
) / sizeof(szAppName
[0]));
128 // Load MsgBox() texts here to avoid loading them many times later
129 LoadString(hInst
, IDS_SOL_ABOUT
, MsgAbout
, sizeof(MsgAbout
) / sizeof(MsgAbout
[0]));
130 LoadString(hInst
, IDS_SOL_QUIT
, MsgQuit
, sizeof(MsgQuit
) / sizeof(MsgQuit
[0]));
131 LoadString(hInst
, IDS_SOL_WIN
, MsgWin
, sizeof(MsgWin
) / sizeof(MsgWin
[0]));
132 LoadString(hInst
, IDS_SOL_DEAL
, MsgDeal
, sizeof(MsgDeal
) / sizeof(MsgDeal
[0]));
134 //Window class for the main application parent window
135 wndclass
.style
= 0;//CS_HREDRAW | CS_VREDRAW;
136 wndclass
.lpfnWndProc
= WndProc
;
137 wndclass
.cbClsExtra
= 0;
138 wndclass
.cbWndExtra
= 0;
139 wndclass
.hInstance
= hInst
;
140 wndclass
.hIcon
= LoadIcon (hInst
, MAKEINTRESOURCE(IDI_SOLITAIRE
));
141 wndclass
.hCursor
= LoadCursor (NULL
, IDC_ARROW
);
142 wndclass
.hbrBackground
= (HBRUSH
)NULL
;
143 wndclass
.lpszMenuName
= MAKEINTRESOURCE(IDR_MENU1
);
144 wndclass
.lpszClassName
= szAppName
;
146 RegisterClass(&wndclass
);
148 ice
.dwSize
= sizeof(ice
);
149 ice
.dwICC
= ICC_BAR_CLASSES
;
150 InitCommonControlsEx(&ice
);
152 srand((unsigned)GetTickCount());//timeGetTime());
158 //Construct the path to our help file
159 MakePath(szHelpPath
, MAX_PATH
, _T(".hlp"));
161 hwnd
= CreateWindow(szAppName
, // window class name
162 szAppName
, // window caption
164 ,//|WS_CLIPCHILDREN, // window style
165 CW_USEDEFAULT
, // initial x position
166 CW_USEDEFAULT
, // initial y position
167 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
168 0, // The real size will be computed in WndProc through WM_GETMINMAXINFO
169 NULL
, // parent window handle
170 NULL
, // use window class menu
171 hInst
, // program instance handle
172 NULL
); // creation parameters
176 ShowWindow(hwnd
, iCmdShow
);
179 hAccelTable
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDR_ACCELERATOR1
));
181 while(GetMessage(&msg
, NULL
,0,0))
183 if(!TranslateAccelerator(hwnd
, hAccelTable
, &msg
))
185 TranslateMessage(&msg
);
186 DispatchMessage(&msg
);
196 INT_PTR CALLBACK
OptionsDlgProc(HWND hDlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
201 CheckRadioButton(hDlg
, IDC_OPT_DRAWONE
, IDC_OPT_DRAWTHREE
,
202 (dwOptions
& OPTION_THREE_CARDS
) ? IDC_OPT_DRAWTHREE
: IDC_OPT_DRAWONE
);
206 (dwOptions
& OPTION_SHOW_STATUS
) ? BST_CHECKED
: BST_UNCHECKED
);
210 switch(LOWORD(wParam
))
213 dwOptions
&= ~OPTION_THREE_CARDS
;
214 if (IsDlgButtonChecked(hDlg
, IDC_OPT_DRAWTHREE
) == BST_CHECKED
)
215 dwOptions
|= OPTION_THREE_CARDS
;
217 if (IsDlgButtonChecked(hDlg
, IDC_OPT_STATUSBAR
) == BST_CHECKED
)
218 dwOptions
|= OPTION_SHOW_STATUS
;
220 dwOptions
&= ~OPTION_SHOW_STATUS
;
222 EndDialog(hDlg
, TRUE
);
226 EndDialog(hDlg
, FALSE
);
234 VOID
ShowGameOptionsDlg(HWND hwnd
)
236 DWORD dwOldOptions
= dwOptions
;
237 RECT rcMain
, rcStatus
;
239 if (DialogBox(hInstance
, MAKEINTRESOURCE(IDD_OPTIONS
), hwnd
, OptionsDlgProc
))
241 if ((dwOldOptions
& OPTION_THREE_CARDS
) != (dwOptions
& OPTION_THREE_CARDS
))
244 if ((dwOldOptions
& OPTION_SHOW_STATUS
) != (dwOptions
& OPTION_SHOW_STATUS
))
246 int nWidth
, nHeight
, nStatusHeight
;
248 GetClientRect(hwndMain
, &rcMain
);
249 nHeight
= rcMain
.bottom
- rcMain
.top
;
250 nWidth
= rcMain
.right
- rcMain
.left
;
252 if (dwOptions
& OPTION_SHOW_STATUS
)
256 ShowWindow(hwndStatus
, SW_SHOW
);
257 GetWindowRect(hwndStatus
, &rcStatus
);
258 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
259 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
-nStatusHeight
, TRUE
);
260 MoveWindow(hwndStatus
, 0, nHeight
-nStatusHeight
, nWidth
, nHeight
, TRUE
);
262 // Force the window to process WM_GETMINMAXINFO again
263 GetWindowRect(hwndMain
, &rc
);
264 SetWindowPos(hwndMain
, NULL
, 0, 0, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, SWP_NOMOVE
| SWP_NOZORDER
);
268 ShowWindow(hwndStatus
, SW_HIDE
);
269 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
277 CardImageWndProc(HWND hwnd
,
282 PCARDBACK pCardBack
= (PCARDBACK
)GetWindowLongPtr(hwnd
,
284 static WNDPROC hOldProc
= NULL
;
286 if (!hOldProc
&& pCardBack
)
287 hOldProc
= pCardBack
->hOldProc
;
296 HBRUSH hBrush
, hOldBrush
;
299 hdc
= BeginPaint(hwnd
, &ps
);
301 if (pCardBack
->bSelected
)
303 hPen
= CreatePen(PS_SOLID
, 2, RGB(0,0,0));
307 DWORD Face
= GetSysColor(COLOR_3DFACE
);
308 hPen
= CreatePen(PS_SOLID
, 2, Face
);
311 GetClientRect(hwnd
, &rc
);
312 hBrush
= (HBRUSH
)GetStockObject(NULL_BRUSH
);
313 hOldPen
= (HPEN
)SelectObject(hdc
, hPen
);
314 hOldBrush
= (HBRUSH
)SelectObject(hdc
, hBrush
);
325 CARDBACK_OPTIONS_WIDTH
,
326 CARDBACK_OPTIONS_HEIGHT
,
328 pCardBack
->hdcNum
* __cardwidth
,
334 SelectObject(hdc
, hOldPen
);
335 SelectObject(hdc
, hOldBrush
);
343 pCardBack
->bSelected
= pCardBack
->bSelected
? FALSE
: TRUE
;
347 return CallWindowProc(hOldProc
,
355 INT_PTR CALLBACK
CardBackDlgProc(HWND hDlg
,
360 static PCARDBACK pCardBacks
= NULL
;
367 SIZE_T size
= sizeof(CARDBACK
) * NUM_CARDBACKS
;
369 pCardBacks
= (PCARDBACK
)HeapAlloc(GetProcessHeap(),
373 for (i
= 0, c
= CARDBACK_START
; c
<= CARDBACK_END
; i
++, c
++)
375 pCardBacks
[i
].hSelf
= GetDlgItem(hDlg
, c
);
376 pCardBacks
[i
].bSelected
= FALSE
;
377 pCardBacks
[i
].hdcNum
= CARDBACK_RES_START
+ i
;
378 pCardBacks
[i
].imgNum
= i
+ 1;
379 pCardBacks
[i
].hOldProc
= (WNDPROC
)SetWindowLongPtr(pCardBacks
[i
].hSelf
,
381 (LONG_PTR
)CardImageWndProc
);
383 SetWindowLongPtr(pCardBacks
[i
].hSelf
,
385 (LONG_PTR
)&pCardBacks
[i
]);
392 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
395 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
397 if (pCardBacks
[i
].bSelected
)
399 num
= pCardBacks
[i
].imgNum
;
403 EndDialog(hDlg
, LOWORD(wParam
) == IDOK
? num
: FALSE
);
404 HeapFree(GetProcessHeap(), 0, pCardBacks
);
408 if (HIWORD(wParam
) == STN_CLICKED
)
412 for (i
= 0; i
< NUM_CARDBACKS
; i
++)
414 if (pCardBacks
[i
].hSelf
== (HWND
)lParam
)
416 pCardBacks
[i
].bSelected
= TRUE
;
419 pCardBacks
[i
].bSelected
= FALSE
;
421 GetClientRect(pCardBacks
[i
].hSelf
, &rc
);
422 InvalidateRect(pCardBacks
[i
].hSelf
, &rc
, TRUE
);
433 VOID
ShowDeckOptionsDlg(HWND hwnd
)
437 if ((cardBack
= DialogBox(hInstance
,
438 MAKEINTRESOURCE(IDD_CARDBACK
),
442 SolWnd
.SetBackCardIdx(CARDBACK_RES_START
+ (cardBack
- 1));
447 //-----------------------------------------------------------------------------
448 LRESULT CALLBACK
WndProc (HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
)
450 static int nWidth
, nHeight
, nStatusHeight
;
456 int parts
[] = { 100, -1 };
459 hwndStatus
= CreateStatusWindow(WS_CHILD
| WS_VISIBLE
| CCS_BOTTOM
| SBARS_SIZEGRIP
, _T("Ready"), hwnd
, 0);
461 //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
463 SendMessage(hwndStatus
, SB_SETPARTS
, 2, (LPARAM
)parts
);
464 SendMessage(hwndStatus
, SB_SETTEXT
, 0 | SBT_NOBORDERS
, (LPARAM
)"");
466 SolWnd
.Create(hwnd
, WS_EX_CLIENTEDGE
, WS_CHILD
|WS_VISIBLE
, 0, 0, 0, 0);
470 // The status bar height is fixed and needed later in WM_SIZE and WM_GETMINMAXINFO
471 // Force the window to process WM_GETMINMAXINFO again
472 GetWindowRect(hwndStatus
, &rcStatus
);
473 nStatusHeight
= rcStatus
.bottom
- rcStatus
.top
;
475 // Hide status bar if options say so
476 if (!(dwOptions
& OPTION_SHOW_STATUS
))
478 ShowWindow(hwndStatus
, SW_HIDE
);
481 SetWindowPos(hwnd
, NULL
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOZORDER
);
485 dwAppStartTime
= GetTickCount();
495 nWidth
= LOWORD(lParam
);
496 nHeight
= HIWORD(lParam
);
498 if (dwOptions
& OPTION_SHOW_STATUS
)
500 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
- nStatusHeight
, TRUE
);
501 MoveWindow(hwndStatus
, 0, nHeight
- nStatusHeight
, nWidth
, nStatusHeight
, TRUE
);
505 MoveWindow(SolWnd
, 0, 0, nWidth
, nHeight
, TRUE
);
507 //parts[0] = nWidth - 256;
508 //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
511 case WM_GETMINMAXINFO
:
515 mmi
= (MINMAXINFO
*)lParam
;
516 mmi
->ptMinTrackSize
.x
= X_BORDER
+ NUM_ROW_STACKS
* (__cardwidth
+ X_ROWSTACK_BORDER
) + X_BORDER
;
517 mmi
->ptMinTrackSize
.y
= GetSystemMetrics(SM_CYCAPTION
) +
518 GetSystemMetrics(SM_CYMENU
) +
522 6 * yRowStackCardOffset
+
525 (dwOptions
& OPTION_SHOW_STATUS
? nStatusHeight
: 0);
530 switch(LOWORD(wParam
))
533 //simulate a button click on the new button..
538 ShowDeckOptionsDlg(hwnd
);
541 case IDM_GAME_OPTIONS
:
542 ShowGameOptionsDlg(hwnd
);
545 case IDM_HELP_CONTENTS
:
546 WinHelp(hwnd
, szHelpPath
, HELP_CONTENTS
, 0);//HELP_KEY, (DWORD)"How to play");
550 MessageBox(hwnd
, MsgAbout
, szAppName
, MB_OK
|MB_ICONINFORMATION
);
554 PostMessage(hwnd
, WM_CLOSE
, 0, 0);
561 if (fGameStarted
== false)
570 ret
= MessageBox(hwnd
, MsgQuit
, szAppName
, MB_YESNO
|MB_ICONQUESTION
);
573 WinHelp(hwnd
, szHelpPath
, HELP_QUIT
, 0);
580 return DefWindowProc (hwnd
, iMsg
, wParam
, lParam
);