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