c8e3e66c148ff343796934a2edc33e42e817f73f
[reactos.git] / rosapps / games / solitaire / solitaire.cpp
1 #include <windows.h>
2 #include <commctrl.h>
3 #include <tchar.h>
4 #include "resource.h"
5 #include "cardlib/cardlib.h"
6
7 #include "solitaire.h"
8
9 TCHAR szHelpPath[MAX_PATH];
10
11 DWORD dwAppStartTime;
12 HWND hwndMain;
13 HWND hwndStatus;
14 HINSTANCE hInstance;
15
16 TCHAR szAppName[] = _T("Solitaire");
17
18 CardWindow SolWnd;
19
20 LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam);
21
22 void MakePath(TCHAR *szDest, UINT nDestLen, TCHAR *szExt)
23 {
24 TCHAR *ptr;
25
26 ptr = szDest + GetModuleFileName(GetModuleHandle(0), szDest, nDestLen) - 1;
27 while(*ptr-- != '.');
28 lstrcpy(ptr + 1, szExt);
29 }
30
31 //
32 // Main entry point
33 //
34 int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrev, PSTR szCmdLine, int iCmdShow)
35 {
36 HWND hwnd;
37 MSG msg;
38 WNDCLASSEX wndclass;
39 INITCOMMONCONTROLSEX ice;
40 HACCEL hAccelTable;
41
42 hInstance = hInst;
43
44 //Window class for the main application parent window
45 wndclass.cbSize = sizeof(wndclass);
46 wndclass.style = 0;//CS_HREDRAW | CS_VREDRAW;
47 wndclass.lpfnWndProc = WndProc;
48 wndclass.cbClsExtra = 0;
49 wndclass.cbWndExtra = 0;
50 wndclass.hInstance = hInst;
51 wndclass.hIcon = LoadIcon (hInst, MAKEINTRESOURCE(IDI_ICON1));
52 wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
53 wndclass.hbrBackground = (HBRUSH)NULL;
54 wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
55 wndclass.lpszClassName = szAppName;
56 wndclass.hIconSm = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);
57
58 RegisterClassEx(&wndclass);
59
60 ice.dwSize = sizeof(ice);
61 ice.dwICC = ICC_BAR_CLASSES;
62 InitCommonControlsEx(&ice);
63
64 srand((unsigned)GetTickCount());//timeGetTime());
65
66 // InitCardLib();
67
68 // LoadSettings();
69
70 //Construct the path to our help file
71 MakePath(szHelpPath, MAX_PATH, _T(".hlp"));
72
73 hwnd = CreateWindow(szAppName, // window class name
74 szAppName, // window caption
75 WS_OVERLAPPEDWINDOW
76 ,//|WS_CLIPCHILDREN, // window style
77 CW_USEDEFAULT, // initial x position
78 CW_USEDEFAULT, // initial y position
79 CW_USEDEFAULT, // initial x size
80 CW_USEDEFAULT, // initial y size
81 NULL, // parent window handle
82 NULL, // use window class menu
83 hInst, // program instance handle
84 NULL); // creation parameters
85
86 hwndMain = hwnd;
87
88 ShowWindow(hwnd, iCmdShow);
89 UpdateWindow(hwnd);
90
91 hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1));
92
93 while(GetMessage(&msg, NULL,0,0))
94 {
95 if(!TranslateAccelerator(hwnd, hAccelTable, &msg))
96 {
97 TranslateMessage(&msg);
98 DispatchMessage(&msg);
99 }
100 }
101
102 // SaveSettings();
103
104 return msg.wParam;
105 }
106
107
108 //-----------------------------------------------------------------------------
109 LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
110 {
111 static int nWidth, nHeight;
112 int nStatusHeight = 0;//20;
113 int parts[] = { 100, -1 };
114 UINT ret;
115
116 MINMAXINFO *mmi;
117
118 switch(iMsg)
119 {
120 case WM_CREATE:
121 hwndStatus = CreateStatusWindow(WS_CHILD | WS_VISIBLE | CCS_BOTTOM | SBARS_SIZEGRIP, "Ready", hwnd, 0);
122
123 //SendMessage(hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0);
124
125 SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
126 SendMessage(hwndStatus, SB_SETTEXT, 0 | SBT_NOBORDERS, (LPARAM)"");
127
128 ShowWindow(hwndStatus, SW_HIDE);
129
130 SolWnd.Create(hwnd, WS_EX_CLIENTEDGE, WS_CHILD|WS_VISIBLE, 0, 0, 0, 0);
131
132 CreateSol();
133
134 NewGame();
135
136 dwAppStartTime = GetTickCount();
137
138 return 0;
139
140 case WM_DESTROY:
141 PostQuitMessage(0);
142 return 0;
143
144 case WM_SIZE:
145 nWidth = LOWORD(lParam);
146 nHeight = HIWORD(lParam);
147
148 MoveWindow(SolWnd, 0, 0, nWidth, nHeight-nStatusHeight, TRUE);
149 //MoveWindow(hwndStatus, 0, nHeight-nStatusHeight, nWidth, nHeight, TRUE);
150 //parts[0] = nWidth - 256;
151 //SendMessage(hwndStatus, SB_SETPARTS, 2, (LPARAM)parts);
152
153 return 0;
154
155 case WM_GETMINMAXINFO:
156 mmi = (MINMAXINFO *)lParam;
157 mmi->ptMinTrackSize.x = 600;
158 mmi->ptMinTrackSize.y = 400;
159
160 return 0;
161
162 case WM_COMMAND:
163
164 switch(LOWORD(wParam))
165 {
166 case IDM_GAME_NEW:
167 //simulate a button click on the new button..
168 NewGame();
169 return 0;
170
171 case IDM_GAME_DECK:
172 //ShowDeckOptionsDlg(hwnd);
173 return 0;
174
175 case IDM_GAME_OPTIONS:
176 //ShowGameOptionsDlg(hwnd);
177 return 0;
178
179 case IDM_HELP_CONTENTS:
180
181 WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play");
182
183 return 0;
184
185 case IDM_HELP_ABOUT:
186 MessageBox(hwnd, _T("Solitare by J Brown\r\n\r\nCardLib version 1.0."), szAppName, MB_OK|MB_ICONINFORMATION);
187
188 return 0;
189
190 case IDM_GAME_EXIT:
191 PostMessage(hwnd, WM_CLOSE, 0, 0);
192 return 0;
193 }
194
195 return 0;
196
197 case WM_CLOSE:
198
199 ret = IDOK;
200
201 if(fGameStarted)
202 {
203 ret = MessageBox(hwnd, _T("Quit the current game?"), szAppName, MB_OKCANCEL|MB_ICONQUESTION);
204 }
205
206 if(ret == IDOK)
207 {
208 WinHelp(hwnd, szHelpPath, HELP_QUIT, 0);
209 DestroyWindow(hwnd);
210 }
211
212 return 0;
213 }
214
215 return DefWindowProc (hwnd, iMsg, wParam, lParam);
216 }
217