Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2331 lines
57 KiB

  1. /* Pegged.C -- Windows Game*/
  2. /* (c) By Mike Blaylock - 1989, 1990 */
  3. #include "windows.h"
  4. #include <port1632.h>
  5. #include "math.h"
  6. #include "pegged.h"
  7. #define DIVISIONS 7
  8. #define ICON_NAME "Pegged"
  9. #define HELP_FILE "pegged.hlp"
  10. VOID checkfvmove();
  11. VOID checkfanymoves();
  12. VOID APIENTRY AboutWEP(HWND, HICON, LPSTR, LPSTR);
  13. RECT r;
  14. INT prevxorg, prevyorg;
  15. INT prevwidth, prevheight;
  16. HWND hWnd ;
  17. HANDLE hAccTable;
  18. INT m = 0, nDefault = 3;
  19. LONG_PTR prevwarea, newarea;
  20. INT xPrevpoint, yPrevpoint, xLeft, yTop;
  21. WPARAM wprevmenuitem;
  22. HANDLE hPeggedIcon;
  23. HANDLE hBitmap, hWBitmap , hIntBitmap, hOldWBitmap, hOldIntBitmap,
  24. hBoardBitmap, hOldBoardBitmap, htmpBitmap, hWtmpBitmap , hInttmpBitmap,
  25. hOldWtmpBitmap, hOldInttmpBitmap, hBoardtmpBitmap, hOldBoardtmpBitmap;
  26. INT icross = 1, iplus = 0, ifireplace = 0, ipyramid = 0, ilamp
  27. = 0, idiamond = 0, iuparrow = 0, isolitaire = 0, fanymoremoves
  28. = 0, ntotal = 0, fignorelbutton = 0, fmousefocusd = 0;
  29. INT ffirst = 1, foomed = 0;
  30. LPSTR lpszCommands[10], lpszHowToPlay[10];
  31. LONG lPrevSizeParam ;
  32. struct {
  33. INT xsource;
  34. INT ysource;
  35. INT xdest;
  36. INT ydest;
  37. INT xjumped;
  38. INT yjumped;
  39. } move[34];
  40. LRESULT APIENTRY WndProc (HWND, UINT, WPARAM, LPARAM) ;
  41. CHAR szAppName [] = "Pegged";
  42. static BOOL bState [DIVISIONS][DIVISIONS];
  43. HDC hDC, hMemDC, hMemwinDC, hIntDC, hBoardDC, htmpMemDC, htmpMemwinDC,
  44. htmpIntDC, htmpBoardDC;
  45. HBRUSH hLtgrybrush, hDkgrybrush, hYbrush, hBbrush, hBlkbrush,
  46. hGbrush, hMedgrybrush;
  47. HPEN hWpen, hLtwpen, hBlkpen, hDkgrypen, hThkdkgrypen, hMedgrypen,
  48. hLtgrypen;
  49. INT first = 1, fhitbutton = 0, fmovingchip = 0, fvalidmove = 0,
  50. fcanundo = 0, foom = 0, foomonsize = 0;
  51. INT ixdownblock, iydownblock, ixupblock, iyupblock, ixkilledblock,
  52. iykilledblock, ixjumpedblock, iyjumpedblock, ixprevsource, iyprevsource,
  53. ixprevdest, iyprevdest, ixprevkilled, iyprevkilled;
  54. MMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  55. /* { */
  56. /* HWND hWnd ;*/
  57. MSG msg ;
  58. WNDCLASS wndclass ;
  59. static INT xScreen, yScreen, xSize, ySize;
  60. /*multinst.c */
  61. if (hPrevInstance)
  62. {
  63. hWnd = FindWindow(szAppName, NULL);
  64. SendMessage(hWnd, WM_SYSCOMMAND, SC_RESTORE, (LONG) 0);
  65. hWnd = GetLastActivePopup(hWnd);
  66. BringWindowToTop(hWnd);
  67. return FALSE;
  68. }
  69. if (!hPrevInstance)
  70. {
  71. wndclass.style = CS_HREDRAW | CS_VREDRAW ;
  72. wndclass.lpfnWndProc = WndProc ;
  73. wndclass.cbClsExtra = 0 ;
  74. wndclass.cbWndExtra = 0 ;
  75. wndclass.hInstance = hInstance ;
  76. wndclass.hIcon = LoadIcon(hInstance, (LPSTR) ICON_NAME);
  77. hPeggedIcon = wndclass.hIcon;
  78. wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  79. wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  80. wndclass.lpszMenuName = szAppName ;
  81. wndclass.lpszClassName = szAppName ;
  82. if (!RegisterClass (&wndclass))
  83. return FALSE ;
  84. }
  85. xScreen = GetSystemMetrics(SM_CXSCREEN);
  86. yScreen = GetSystemMetrics(SM_CYSCREEN);
  87. if (xScreen > yScreen)
  88. {
  89. xSize = (xScreen / 8) * 3;
  90. ySize = xSize;
  91. } else
  92. {
  93. ySize = (yScreen / 8) * 3;
  94. xSize = ySize;
  95. }
  96. hWnd = CreateWindow (szAppName, "Pegged",
  97. WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX,
  98. (xScreen-xSize)
  99. / 2, (yScreen-ySize)
  100. / 2,
  101. xSize, ySize,
  102. NULL, NULL, hInstance, NULL) ;
  103. ShowWindow (hWnd, nCmdShow) ;
  104. UpdateWindow (hWnd) ;
  105. hAccTable = LoadAccelerators(hInstance, "MainAcc");
  106. while (GetMessage (&msg, NULL, 0, 0)
  107. )
  108. if (!TranslateAccelerator(hWnd, hAccTable, &msg)
  109. )
  110. {
  111. {
  112. TranslateMessage (&msg) ;
  113. DispatchMessage (&msg) ;
  114. }
  115. }
  116. return (INT) msg.wParam ;
  117. }
  118. LRESULT APIENTRY WndProc (
  119. HWND hWnd,
  120. UINT iMessage,
  121. WPARAM wParam,
  122. LPARAM lParam)
  123. {
  124. static INT xBlock, xsizedBlock, yBlock, ysizedBlock, xEdge,
  125. yEdge, xShadow, yShadow, xHalf, yHalf, winxEdge, winyEdge;
  126. HDC hDC;
  127. PAINTSTRUCT ps;
  128. RECT rect;
  129. LONG xul, yul;
  130. INT x, y, j, k;
  131. static INT xClient, xsizedClient, yClient, ysizedClient,
  132. xCenter, yCenter, oldxCenter, oldyCenter, xTotal, yTotal,
  133. xRadius, yRadius, xMove, yMove, xPixel, yPixel, i;
  134. INT xPoint, yPoint, xUp, yUp;
  135. SHORT nScale;
  136. BOOL bShow;
  137. MSG message;
  138. HMENU hMenu;
  139. switch (iMessage) {
  140. case WM_INITMENUPOPUP:
  141. if (m)
  142. EnableMenuItem((HMENU)wParam, IDM_UNDO, MF_ENABLED);
  143. else
  144. EnableMenuItem((HMENU)wParam, IDM_UNDO, MF_GRAYED);
  145. break;
  146. case WM_COMMAND:
  147. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  148. case IDM_NEW:
  149. m = 0;
  150. hDC = GetDC(hWnd);
  151. if (isolitaire) {
  152. for (j = 0; j < 7; ++j)
  153. for (k = 0; k < 7; ++k) {
  154. if ((j > 1 && j < 5) || (k > 1 && k < 5))
  155. if (!(j == 3 && k == 3))
  156. bState[j][k] = 1;
  157. else
  158. bState[j][k] = 0;
  159. }
  160. }
  161. if (icross) {
  162. bState[0][2] = 0;
  163. bState[0][3] = 0;
  164. bState[0][4] = 0;
  165. bState[1][2] = 0;
  166. bState[1][3] = 0;
  167. bState[1][4] = 0;
  168. bState[2][0] = 0;
  169. bState[2][1] = 0;
  170. bState[2][2] = 1;
  171. bState[2][3] = 0;
  172. bState[2][4] = 0;
  173. bState[2][5] = 0;
  174. bState[2][6] = 0;
  175. bState[3][0] = 0;
  176. bState[3][1] = 1;
  177. bState[3][2] = 1;
  178. bState[3][3] = 1;
  179. bState[3][4] = 1;
  180. bState[3][5] = 0;
  181. bState[3][6] = 0;
  182. bState[4][0] = 0;
  183. bState[4][1] = 0;
  184. bState[4][2] = 1;
  185. bState[4][3] = 0;
  186. bState[4][4] = 0;
  187. bState[4][5] = 0;
  188. bState[4][6] = 0;
  189. bState[5][2] = 0;
  190. bState[5][3] = 0;
  191. bState[5][4] = 0;
  192. bState[6][2] = 0;
  193. bState[6][3] = 0;
  194. bState[6][4] = 0;
  195. }
  196. if (iuparrow) {
  197. bState[0][2] = 0;
  198. bState[0][3] = 0;
  199. bState[0][4] = 0;
  200. bState[1][2] = 1;
  201. bState[1][3] = 0;
  202. bState[1][4] = 0;
  203. bState[2][0] = 0;
  204. bState[2][1] = 1;
  205. bState[2][2] = 1;
  206. bState[2][3] = 0;
  207. bState[2][4] = 0;
  208. bState[2][5] = 1;
  209. bState[2][6] = 1;
  210. bState[3][0] = 1;
  211. bState[3][1] = 1;
  212. bState[3][2] = 1;
  213. bState[3][3] = 1;
  214. bState[3][4] = 1;
  215. bState[3][5] = 1;
  216. bState[3][6] = 1;
  217. bState[4][0] = 0;
  218. bState[4][1] = 1;
  219. bState[4][2] = 1;
  220. bState[4][3] = 0;
  221. bState[4][4] = 0;
  222. bState[4][5] = 1;
  223. bState[4][6] = 1;
  224. bState[5][2] = 1;
  225. bState[5][3] = 0;
  226. bState[5][4] = 0;
  227. bState[6][2] = 0;
  228. bState[6][3] = 0;
  229. bState[6][4] = 0;
  230. }
  231. if (iplus) {
  232. bState[0][2] = 0;
  233. bState[0][3] = 0;
  234. bState[0][4] = 0;
  235. bState[1][2] = 0;
  236. bState[1][3] = 1;
  237. bState[1][4] = 0;
  238. bState[2][0] = 0;
  239. bState[2][1] = 0;
  240. bState[2][2] = 0;
  241. bState[2][3] = 1;
  242. bState[2][4] = 0;
  243. bState[2][5] = 0;
  244. bState[2][6] = 0;
  245. bState[3][0] = 0;
  246. bState[3][1] = 1;
  247. bState[3][2] = 1;
  248. bState[3][3] = 1;
  249. bState[3][4] = 1;
  250. bState[3][5] = 1;
  251. bState[3][6] = 0;
  252. bState[4][0] = 0;
  253. bState[4][1] = 0;
  254. bState[4][2] = 0;
  255. bState[4][3] = 1;
  256. bState[4][4] = 0;
  257. bState[4][5] = 0;
  258. bState[4][6] = 0;
  259. bState[5][2] = 0;
  260. bState[5][3] = 1;
  261. bState[5][4] = 0;
  262. bState[6][2] = 0;
  263. bState[6][3] = 0;
  264. bState[6][4] = 0;
  265. }
  266. if (ifireplace) {
  267. bState[0][2] = 0;
  268. bState[0][3] = 0;
  269. bState[0][4] = 0;
  270. bState[1][2] = 0;
  271. bState[1][3] = 0;
  272. bState[1][4] = 0;
  273. bState[2][0] = 1;
  274. bState[2][1] = 1;
  275. bState[2][2] = 1;
  276. bState[2][3] = 1;
  277. bState[2][4] = 0;
  278. bState[2][5] = 0;
  279. bState[2][6] = 0;
  280. bState[3][0] = 1;
  281. bState[3][1] = 1;
  282. bState[3][2] = 1;
  283. bState[3][3] = 0;
  284. bState[3][4] = 0;
  285. bState[3][5] = 0;
  286. bState[3][6] = 0;
  287. bState[4][0] = 1;
  288. bState[4][1] = 1;
  289. bState[4][2] = 1;
  290. bState[4][3] = 1;
  291. bState[4][4] = 0;
  292. bState[4][5] = 0;
  293. bState[4][6] = 0;
  294. bState[5][2] = 0;
  295. bState[5][3] = 0;
  296. bState[5][4] = 0;
  297. bState[6][2] = 0;
  298. bState[6][3] = 0;
  299. bState[6][4] = 0;
  300. }
  301. if (ipyramid) {
  302. bState[0][2] = 0;
  303. bState[0][3] = 0;
  304. bState[0][4] = 1;
  305. bState[1][2] = 0;
  306. bState[1][3] = 1;
  307. bState[1][4] = 1;
  308. bState[2][0] = 0;
  309. bState[2][1] = 0;
  310. bState[2][2] = 1;
  311. bState[2][3] = 1;
  312. bState[2][4] = 1;
  313. bState[2][5] = 0;
  314. bState[2][6] = 0;
  315. bState[3][0] = 0;
  316. bState[3][1] = 1;
  317. bState[3][2] = 1;
  318. bState[3][3] = 1;
  319. bState[3][4] = 1;
  320. bState[3][5] = 0;
  321. bState[3][6] = 0;
  322. bState[4][0] = 0;
  323. bState[4][1] = 0;
  324. bState[4][2] = 1;
  325. bState[4][3] = 1;
  326. bState[4][4] = 1;
  327. bState[4][5] = 0;
  328. bState[4][6] = 0;
  329. bState[5][2] = 0;
  330. bState[5][3] = 1;
  331. bState[5][4] = 1;
  332. bState[6][2] = 0;
  333. bState[6][3] = 0;
  334. bState[6][4] = 1;
  335. }
  336. if (idiamond) {
  337. bState[0][2] = 0;
  338. bState[0][3] = 1;
  339. bState[0][4] = 0;
  340. bState[1][2] = 1;
  341. bState[1][3] = 1;
  342. bState[1][4] = 1;
  343. bState[2][0] = 0;
  344. bState[2][1] = 1;
  345. bState[2][2] = 1;
  346. bState[2][3] = 1;
  347. bState[2][4] = 1;
  348. bState[2][5] = 1;
  349. bState[2][6] = 0;
  350. bState[3][0] = 1;
  351. bState[3][1] = 1;
  352. bState[3][2] = 1;
  353. bState[3][3] = 0;
  354. bState[3][4] = 1;
  355. bState[3][5] = 1;
  356. bState[3][6] = 1;
  357. bState[4][0] = 0;
  358. bState[4][1] = 1;
  359. bState[4][2] = 1;
  360. bState[4][3] = 1;
  361. bState[4][4] = 1;
  362. bState[4][5] = 1;
  363. bState[4][6] = 0;
  364. bState[5][2] = 1;
  365. bState[5][3] = 1;
  366. bState[5][4] = 1;
  367. bState[6][2] = 0;
  368. bState[6][3] = 1;
  369. bState[6][4] = 0;
  370. }
  371. /******Erase all the chips *************************************/
  372. for (x = 0; x < DIVISIONS; x++)
  373. for (y = 0; y < DIVISIONS; y++) {
  374. if ((x > 1 && x < 5) || (y > 1 && y < 5)) {
  375. BitBlt(hDC, xBlock * x + winxEdge, yBlock
  376. *y + winyEdge, xBlock, yBlock, hBoardDC,
  377. xBlock * x + winxEdge, yBlock * y + winyEdge,
  378. SRCCOPY);
  379. }
  380. }
  381. /*************************************************************/
  382. /********* Put chips where they go *****************************/
  383. for (x = 0; x < DIVISIONS; x++)
  384. for (y = 0; y < DIVISIONS; y++) {
  385. if (bState[x][y]) {
  386. SelectObject(hDC, hDkgrypen);
  387. SelectObject(hDC, hDkgrybrush);
  388. Ellipse(hDC, x * xBlock + xEdge + xShadow +
  389. winxEdge, y * yBlock + yEdge + yShadow +
  390. winyEdge, (x + 1) * xBlock - xEdge + xShadow +
  391. winxEdge, (y + 1) * yBlock - yEdge + yShadow +
  392. winyEdge);
  393. SelectObject(hDC, hBlkpen);
  394. SelectObject(hDC, hBbrush);
  395. Ellipse(hDC, x * xBlock + xEdge + winxEdge,
  396. y * yBlock + yEdge + winyEdge, (x + 1) *
  397. xBlock - xEdge + winxEdge, (y + 1) * yBlock -
  398. yEdge + winyEdge);
  399. SelectObject(hDC, hWpen);
  400. Arc(hDC, x * xBlock + xEdge + xShadow +
  401. winxEdge, y * yBlock + yEdge + yShadow +
  402. winyEdge, (x + 1) * xBlock - xEdge - xShadow +
  403. winxEdge, (y + 1) * yBlock - yEdge - yShadow +
  404. winyEdge , x * xBlock + xHalf + winxEdge ,
  405. y * yBlock + yShadow + winyEdge, x * xBlock
  406. + xShadow + winxEdge, y * yBlock + yHalf +
  407. winyEdge);
  408. }
  409. }
  410. /***************************************************************/
  411. BitBlt(hMemwinDC, 0, 0, xClient, yClient, hDC, 0, 0,
  412. SRCCOPY);
  413. ReleaseDC(hWnd, hDC);
  414. break;
  415. case IDM_UNDO:
  416. if (m) {
  417. --m;
  418. /*put a chip back in the original location */
  419. hDC = GetDC(hWnd);
  420. /*erase the destination chip on screen*/
  421. BitBlt(hDC, move[m].xdest * xBlock + winxEdge,
  422. move[m].ydest * yBlock + winyEdge, xBlock, yBlock,
  423. hBoardDC, move[m].xdest * xBlock + winxEdge, move[m].ydest
  424. *yBlock + winyEdge , SRCCOPY);
  425. /*Erase the destination chip on the memdc */
  426. SelectObject(hMemwinDC, hWBitmap);
  427. BitBlt(hMemwinDC, move[m].xdest * xBlock + winxEdge,
  428. move[m].ydest * yBlock + winyEdge, xBlock, yBlock,
  429. hBoardDC, move[m].xdest * xBlock + winxEdge, move[m].ydest
  430. *yBlock + winyEdge , SRCCOPY);
  431. /*Put back the jumped chip on the screen*/
  432. x = move[m].xjumped;
  433. y = move[m].yjumped;
  434. SelectObject(hDC, hDkgrypen);
  435. SelectObject(hDC, hDkgrybrush);
  436. Ellipse(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  437. y * yBlock + yEdge + yShadow + winyEdge, (x +
  438. 1) * xBlock - xEdge + xShadow + winxEdge, (y +
  439. 1) * yBlock - yEdge + yShadow + winyEdge);
  440. SelectObject(hDC, hBlkpen);
  441. SelectObject(hDC, hBbrush);
  442. Ellipse(hDC, x * xBlock + xEdge + winxEdge, y *
  443. yBlock + yEdge + winyEdge, (x + 1) * xBlock - xEdge +
  444. winxEdge, (y + 1) * yBlock - yEdge + winyEdge);
  445. SelectObject(hDC, hWpen);
  446. Arc(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  447. y * yBlock + yEdge + yShadow + winyEdge, (x +
  448. 1) * xBlock - xEdge - xShadow + winxEdge, (y +
  449. 1) * yBlock - yEdge - yShadow + winyEdge , x *
  450. xBlock + xHalf + winxEdge , y * yBlock + yShadow +
  451. winyEdge, x * xBlock + xShadow + winxEdge, y *
  452. yBlock + yHalf + winyEdge);
  453. /* Put back the jumped chip in the memdc */
  454. SelectObject(hMemwinDC, hWBitmap);
  455. BitBlt(hMemwinDC, move[m].xjumped * xBlock + winxEdge,
  456. move[m].yjumped * yBlock + winyEdge, xBlock, yBlock,
  457. hDC, move[m].xjumped * xBlock + winxEdge, move[m].yjumped
  458. *yBlock + winyEdge , SRCCOPY);
  459. /*Put back the source chip on the screen*/
  460. x = move[m].xsource;
  461. y = move[m].ysource;
  462. SelectObject(hDC, hDkgrypen);
  463. SelectObject(hDC, hDkgrybrush);
  464. Ellipse(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  465. y * yBlock + yEdge + yShadow + winyEdge, (x +
  466. 1) * xBlock - xEdge + xShadow + winxEdge, (y +
  467. 1) * yBlock - yEdge + yShadow + winyEdge);
  468. SelectObject(hDC, hBlkpen);
  469. SelectObject(hDC, hBbrush);
  470. Ellipse(hDC, x * xBlock + xEdge + winxEdge, y *
  471. yBlock + yEdge + winyEdge, (x + 1) * xBlock - xEdge +
  472. winxEdge, (y + 1) * yBlock - yEdge + winyEdge);
  473. SelectObject(hDC, hWpen);
  474. Arc(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  475. y * yBlock + yEdge + yShadow + winyEdge, (x +
  476. 1) * xBlock - xEdge - xShadow + winxEdge, (y +
  477. 1) * yBlock - yEdge - yShadow + winyEdge , x *
  478. xBlock + xHalf + winxEdge , y * yBlock + yShadow +
  479. winyEdge, x * xBlock + xShadow + winxEdge, y *
  480. yBlock + yHalf + winyEdge);
  481. /* Put back the source chip in the memdc */
  482. SelectObject(hMemwinDC, hWBitmap);
  483. BitBlt(hMemwinDC, move[m].xsource * xBlock + winxEdge,
  484. move[m].ysource * yBlock + winyEdge, xBlock, yBlock,
  485. hDC, move[m].xsource * xBlock + winxEdge, move[m].ysource
  486. *yBlock + winyEdge , SRCCOPY);
  487. /*Restore the matrix to previous state*/
  488. bState[move[m].xsource][move[m].ysource] = 1;
  489. bState[move[m].xjumped][move[m].yjumped] = 1;
  490. bState[move[m].xdest][move[m].ydest] = 0;
  491. ReleaseDC(hWnd, hDC);
  492. } else
  493. MessageBox(hWnd, "Can't Backup", szAppName, MB_ICONASTERISK |
  494. MB_OK);
  495. break;
  496. case IDM_CROSS:
  497. icross = 1;
  498. iplus = 0;
  499. ifireplace = 0;
  500. ipyramid = 0;
  501. ilamp = 0;
  502. idiamond = 0;
  503. iuparrow = 0;
  504. isolitaire = 0;
  505. hMenu = GetMenu(hWnd);
  506. CheckMenuItem(hMenu, (WORD)wprevmenuitem, MF_UNCHECKED);
  507. CheckMenuItem(hMenu, IDM_CROSS, MF_CHECKED);
  508. wprevmenuitem = wParam;
  509. PostMessage(hWnd, WM_COMMAND, IDM_NEW, 0L);
  510. break;
  511. case IDM_PLUS:
  512. iplus = 1;
  513. icross = 0;
  514. ifireplace = 0;
  515. ipyramid = 0;
  516. ilamp = 0;
  517. idiamond = 0;
  518. iuparrow = 0;
  519. isolitaire = 0;
  520. hMenu = GetMenu(hWnd);
  521. CheckMenuItem(hMenu, (WORD)wprevmenuitem, MF_UNCHECKED);
  522. CheckMenuItem(hMenu, (WORD)wParam, MF_CHECKED);
  523. wprevmenuitem = wParam;
  524. PostMessage(hWnd, WM_COMMAND, IDM_NEW, 0L);
  525. break;
  526. case IDM_FIREPLACE:
  527. iplus = 0;
  528. icross = 0;
  529. ifireplace = 1;
  530. ipyramid = 0;
  531. ilamp = 0;
  532. idiamond = 0;
  533. iuparrow = 0;
  534. isolitaire = 0;
  535. hMenu = GetMenu(hWnd);
  536. CheckMenuItem(hMenu, (WORD)wprevmenuitem, MF_UNCHECKED);
  537. CheckMenuItem(hMenu, (WORD)wParam, MF_CHECKED);
  538. wprevmenuitem = wParam;
  539. PostMessage(hWnd, WM_COMMAND, IDM_NEW, 0L);
  540. break;
  541. case IDM_UPARROW:
  542. iplus = 0;
  543. icross = 0;
  544. ifireplace = 0;
  545. ipyramid = 0;
  546. ilamp = 0;
  547. idiamond = 0;
  548. iuparrow = 1;
  549. isolitaire = 0;
  550. hMenu = GetMenu(hWnd);
  551. CheckMenuItem(hMenu, (WORD)wprevmenuitem, MF_UNCHECKED);
  552. CheckMenuItem(hMenu, (WORD)wParam, MF_CHECKED);
  553. wprevmenuitem = wParam;
  554. PostMessage(hWnd, WM_COMMAND, IDM_NEW, 0L);
  555. break;
  556. case IDM_DIAMOND:
  557. iplus = 0;
  558. icross = 0;
  559. ifireplace = 0;
  560. ipyramid = 0;
  561. ilamp = 0;
  562. idiamond = 1;
  563. iuparrow = 0;
  564. isolitaire = 0;
  565. hMenu = GetMenu(hWnd);
  566. CheckMenuItem(hMenu, (WORD)wprevmenuitem, MF_UNCHECKED);
  567. CheckMenuItem(hMenu, (WORD)wParam, MF_CHECKED);
  568. wprevmenuitem = wParam;
  569. PostMessage(hWnd, WM_COMMAND, IDM_NEW, 0L);
  570. break;
  571. case IDM_PYRAMID:
  572. iplus = 0;
  573. icross = 0;
  574. ifireplace = 0;
  575. ipyramid = 1;
  576. ilamp = 0;
  577. idiamond = 0;
  578. iuparrow = 0;
  579. isolitaire = 0;
  580. hMenu = GetMenu(hWnd);
  581. CheckMenuItem(hMenu, (WORD)wprevmenuitem, MF_UNCHECKED);
  582. CheckMenuItem(hMenu, (WORD)wParam, MF_CHECKED);
  583. wprevmenuitem = wParam;
  584. PostMessage(hWnd, WM_COMMAND, IDM_NEW, 0L);
  585. break;
  586. case IDM_SOLITAIRE:
  587. iplus = 0;
  588. icross = 0;
  589. ifireplace = 0;
  590. ipyramid = 0;
  591. ilamp = 0;
  592. idiamond = 0;
  593. iuparrow = 0;
  594. isolitaire = 1;
  595. hMenu = GetMenu(hWnd);
  596. CheckMenuItem(hMenu, (WORD)wprevmenuitem, MF_UNCHECKED);
  597. CheckMenuItem(hMenu, (WORD)wParam, MF_CHECKED);
  598. wprevmenuitem = wParam;
  599. PostMessage(hWnd, WM_COMMAND, IDM_NEW, 0L);
  600. break;
  601. case IDM_ABOUT:
  602. AboutWEP(hWnd, hPeggedIcon , "Pegged! Version 1.0",
  603. "by Mike Blaylock");
  604. /*
  605. MessageBox(hWnd,"Pegged\n\nA Windows Solitaire Game\n\nCopyright 1989-90\n\nby Mike Blaylock\n\nAlpha v1.011",szAppName, MB_ICONASTERISK | MB_OK);
  606. */
  607. break;
  608. case IDM_INDEX:
  609. WinHelp(hWnd, HELP_FILE, HELP_INDEX, (ULONG_PTR) NULL);
  610. break;
  611. case IDM_HOWTO:
  612. WinHelp(hWnd, HELP_FILE, HELP_KEY, (ULONG_PTR) "How To Play");
  613. break;
  614. case IDM_COMMANDS:
  615. WinHelp(hWnd, HELP_FILE, HELP_KEY, (ULONG_PTR) "Commands");
  616. break;
  617. case IDM_USING:
  618. WinHelp(hWnd, HELP_FILE, HELP_HELPONHELP, (ULONG_PTR) NULL);
  619. break;
  620. case IDM_ICONIZE:
  621. ShowWindow(hWnd, SW_MINIMIZE);
  622. break;
  623. case IDM_EXIT:
  624. DestroyWindow(hWnd);
  625. break;
  626. default:
  627. break;
  628. }
  629. break;
  630. case WM_CREATE:
  631. hDC = GetDC (hWnd) ;
  632. xPixel = GetDeviceCaps (hDC, ASPECTX) ;
  633. yPixel = GetDeviceCaps (hDC, ASPECTY) ;
  634. hWpen = CreatePen(0, 2, RGB(255, 255, 255));
  635. hLtwpen = CreatePen(0, 1, RGB(255, 255, 255));
  636. hMedgrypen = CreatePen(0, 1, RGB (128, 128, 128));
  637. hDkgrypen = CreatePen(0, 1, RGB (64, 64, 64));
  638. hThkdkgrypen = CreatePen(0, 2, RGB (64, 64, 64));
  639. hMedgrybrush = CreateSolidBrush(RGB (128, 128, 128));
  640. hDkgrybrush = CreateSolidBrush(RGB (64, 64, 64));
  641. hBlkpen = GetStockObject(BLACK_PEN);
  642. hBbrush = CreateSolidBrush (RGB (0, 0, 255));
  643. hBlkbrush = CreateSolidBrush(RGB (0, 0, 0));
  644. hGbrush = CreateSolidBrush (RGB (0, 64, 0));
  645. hLtgrybrush = CreateSolidBrush (RGB (192, 192, 192));
  646. hLtgrypen = CreatePen(0, 1, RGB (192, 192, 192));
  647. hYbrush = CreateSolidBrush (RGB (255, 255, 0));
  648. nDefault = 3;
  649. hMenu = GetMenu(hWnd);
  650. wprevmenuitem = GetPrivateProfileInt((LPSTR)"Pegged", (LPSTR)"Option",
  651. nDefault, (LPSTR)"entpack.ini");
  652. CheckMenuItem(hMenu, (WORD)wprevmenuitem
  653. , MF_CHECKED);
  654. icross = 0;
  655. iplus = 0;
  656. ifireplace = 0;
  657. ipyramid = 0;
  658. idiamond = 0;
  659. iuparrow = 0;
  660. isolitaire = 0;
  661. switch (wprevmenuitem) {
  662. case 3:
  663. icross = 1;
  664. break;
  665. case 4:
  666. iplus = 1;
  667. break;
  668. case 5:
  669. ifireplace = 1;
  670. break;
  671. case 6:
  672. iuparrow = 1;
  673. break;
  674. case 7:
  675. ipyramid = 1;
  676. break;
  677. case 8:
  678. idiamond = 1;
  679. break;
  680. case 9:
  681. isolitaire = 1;
  682. break;
  683. default:
  684. icross = 1;
  685. break;
  686. }
  687. PostMessage(hWnd, WM_COMMAND, IDM_NEW, 0L);
  688. ffirst = 1;
  689. ReleaseDC (hWnd, hDC) ;
  690. break ;
  691. case WM_SIZE:
  692. foom = 0;
  693. hDC = GetDC (hWnd) ;
  694. MGetViewportOrg(hDC, &xLeft, &yTop);
  695. newarea = (LONG)LOWORD(lParam) * (LONG)HIWORD(lParam);
  696. if (ffirst) {
  697. xBlock = LOWORD (lParam) / (DIVISIONS + 2);
  698. yBlock = HIWORD (lParam) / (DIVISIONS + 2);
  699. xClient = LOWORD (lParam);
  700. yClient = HIWORD (lParam);
  701. xEdge = xBlock / 4;
  702. yEdge = yBlock / 4;
  703. xShadow = xBlock / 10;
  704. yShadow = yBlock / 10;
  705. xHalf = xBlock / 2;
  706. yHalf = yBlock / 2;
  707. winxEdge = xBlock;
  708. winyEdge = yBlock;
  709. if (!(hIntDC = CreateCompatibleDC(hDC))) {
  710. MessageBox(hWnd, "Not Enough Memory", szAppName,
  711. MB_ICONASTERISK | MB_OK);
  712. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  713. break;
  714. }
  715. if (!(hBoardBitmap = CreateCompatibleBitmap(hDC, xClient,
  716. yClient))) {
  717. MessageBox(hWnd, "Not Enough Memory", szAppName,
  718. MB_ICONASTERISK | MB_OK);
  719. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  720. break;
  721. }
  722. if (!(hIntBitmap = CreateCompatibleBitmap(hDC, xBlock
  723. *4, yBlock * 4))) {
  724. MessageBox(hWnd, "Not Enough Memory", szAppName,
  725. MB_ICONASTERISK | MB_OK);
  726. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  727. break;
  728. }
  729. if (!(hMemwinDC = CreateCompatibleDC(hDC))) {
  730. MessageBox(hWnd, "Not Enough Memory", szAppName,
  731. MB_ICONASTERISK | MB_OK);
  732. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  733. break;
  734. }
  735. if (!(hBoardDC = CreateCompatibleDC(hDC))) {
  736. MessageBox(hWnd, "Not Enough Memory", szAppName,
  737. MB_ICONASTERISK | MB_OK);
  738. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  739. break;
  740. }
  741. if (!(hWBitmap = CreateCompatibleBitmap(hDC, xClient,
  742. yClient))) {
  743. MessageBox(hWnd, "Not Enough Memory", szAppName,
  744. MB_ICONASTERISK | MB_OK);
  745. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  746. break;
  747. }
  748. hOldIntBitmap = SelectObject(hIntDC, hIntBitmap);
  749. hOldWBitmap = SelectObject(hMemwinDC, hWBitmap);
  750. hOldBoardBitmap = SelectObject(hBoardDC, hBoardBitmap);
  751. }
  752. xsizedClient = LOWORD (lParam);
  753. ysizedClient = HIWORD (lParam);
  754. xsizedBlock = LOWORD (lParam) / (DIVISIONS + 2);
  755. ysizedBlock = HIWORD (lParam) / (DIVISIONS + 2);
  756. /*If we are actually sizing and not simply being restored from running OOM on a previous size attempt, see if there is enough memory for all the new bitmaps for the new size by trying to create temporary versions of all the bitmaps and DC's*/
  757. if ((!foomonsize) && (newarea > prevwarea) && (!ffirst)) {
  758. if (!(hBoardtmpBitmap = CreateCompatibleBitmap(hDC,
  759. xsizedClient, ysizedClient))) {
  760. foomonsize = 1;
  761. }
  762. if (!foomonsize)
  763. if (!(htmpBoardDC = CreateCompatibleDC(hDC))) {
  764. foomonsize = 1;
  765. DeleteObject(hBoardtmpBitmap);
  766. }
  767. if (!foomonsize)
  768. if (!(hWtmpBitmap = CreateCompatibleBitmap(hDC,
  769. xsizedClient, ysizedClient))) {
  770. foomonsize = 1;
  771. SelectObject(htmpBoardDC, hBoardtmpBitmap);
  772. DeleteDC(htmpBoardDC);
  773. DeleteObject(hBoardtmpBitmap);
  774. }
  775. if (!foomonsize)
  776. if (!(htmpMemwinDC = CreateCompatibleDC(hDC))) {
  777. foomonsize = 1;
  778. SelectObject(htmpBoardDC, hBoardtmpBitmap);
  779. DeleteDC(htmpBoardDC);
  780. DeleteObject(hBoardtmpBitmap);
  781. DeleteObject(hWtmpBitmap);
  782. }
  783. if (!foomonsize)
  784. if (!(hInttmpBitmap = CreateCompatibleBitmap(hDC,
  785. xsizedBlock * 4, ysizedBlock * 4))) {
  786. foomonsize = 1;
  787. SelectObject(htmpBoardDC, hBoardtmpBitmap);
  788. DeleteDC(htmpBoardDC);
  789. DeleteObject(hBoardtmpBitmap);
  790. SelectObject(htmpMemwinDC, hWtmpBitmap);
  791. DeleteDC(htmpMemwinDC);
  792. DeleteObject(hWtmpBitmap);
  793. }
  794. if (!foomonsize)
  795. if (!(htmpIntDC = CreateCompatibleDC(hDC))) {
  796. foomonsize = 1;
  797. SelectObject(htmpBoardDC, hBoardtmpBitmap);
  798. DeleteDC(htmpBoardDC);
  799. DeleteObject(hBoardtmpBitmap);
  800. SelectObject(htmpMemwinDC, hWtmpBitmap);
  801. DeleteDC(htmpMemwinDC);
  802. DeleteObject(hWtmpBitmap);
  803. DeleteObject(hInttmpBitmap);
  804. }
  805. if (foomonsize)
  806. foomed = 1;
  807. /*If there isn't enough memory do a MoveWindow to the old size, and break*/
  808. if (foomonsize) {
  809. ReleaseDC(hWnd, hDC);
  810. MoveWindow(hWnd, prevxorg, prevyorg, prevwidth,
  811. prevheight, TRUE);
  812. break;
  813. }
  814. /*If there IS enough memory, destroy the temp bitmaps and DC's and continue*/
  815. else
  816. {
  817. SelectObject(htmpBoardDC, hBoardtmpBitmap);
  818. DeleteDC(htmpBoardDC);
  819. DeleteObject(hBoardtmpBitmap);
  820. SelectObject(htmpMemwinDC, hWtmpBitmap);
  821. DeleteDC(htmpMemwinDC);
  822. DeleteObject(hWtmpBitmap);
  823. SelectObject(htmpIntDC, hInttmpBitmap);
  824. DeleteDC(htmpIntDC);
  825. DeleteObject(hInttmpBitmap);
  826. }
  827. }/*End if not previous foomonsize and sizing smaller and not first time*/
  828. if ((!ffirst) && (!foomonsize))/*if this isn't the first start and we're not restoring from previous failed size */ {
  829. SelectObject(hBoardDC, hOldBoardBitmap);
  830. DeleteDC(hBoardDC);
  831. }
  832. if ((!ffirst) && (!foomonsize)) {
  833. SelectObject(hIntDC, hOldIntBitmap);
  834. DeleteDC(hIntDC);
  835. }
  836. if ((!ffirst) && (!foomonsize)) {
  837. SelectObject(hMemwinDC, hOldWBitmap);
  838. DeleteDC(hMemwinDC);
  839. }
  840. if ((!ffirst) && (!foomonsize))
  841. DeleteObject(hWBitmap);
  842. if ((!ffirst) && (!foomonsize))
  843. DeleteObject(hOldWBitmap);
  844. if ((!ffirst) && (!foomonsize))
  845. DeleteObject(hIntBitmap);
  846. if ((!ffirst) && (!foomonsize))
  847. DeleteObject(hOldIntBitmap);
  848. if ((!ffirst) && (!foomonsize))
  849. DeleteObject(hBoardBitmap);
  850. if ((!ffirst) && (!foomonsize))
  851. DeleteObject(hOldBoardBitmap);
  852. if ((!ffirst) && (!foomonsize)) /*this assumes the test for enough memory works and update the size of the client area*/ {
  853. xBlock = LOWORD (lParam) / (DIVISIONS + 2);
  854. yBlock = HIWORD (lParam) / (DIVISIONS + 2);
  855. xClient = LOWORD (lParam);
  856. yClient = HIWORD (lParam);
  857. xEdge = xBlock / 4;
  858. yEdge = yBlock / 4;
  859. xShadow = xBlock / 10;
  860. yShadow = yBlock / 10;
  861. xHalf = xBlock / 2;
  862. yHalf = yBlock / 2;
  863. winxEdge = xBlock;
  864. winyEdge = yBlock;
  865. }
  866. if ((!ffirst) && (!foomonsize))
  867. if (!(hBoardBitmap = CreateCompatibleBitmap(hDC, xClient,
  868. yClient))) {
  869. foom = 1;
  870. MessageBox(hWnd, "Out of Memory ", szAppName, MB_ICONASTERISK |
  871. MB_OK);
  872. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  873. ReleaseDC(hWnd, hDC);
  874. break;
  875. }
  876. if ((!ffirst) && (!foomonsize))
  877. if (!(hBoardDC = CreateCompatibleDC(hDC))) {
  878. foom = 1;
  879. MessageBox(hWnd, "Out of Memory ", szAppName, MB_ICONASTERISK |
  880. MB_OK);
  881. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  882. ReleaseDC(hWnd, hDC);
  883. break;
  884. }
  885. if ((!ffirst) && (!foomonsize))
  886. if (!(hMemwinDC = CreateCompatibleDC(hDC))) {
  887. foom = 1;
  888. MessageBox(hWnd, "Out of Memory ", szAppName, MB_ICONASTERISK |
  889. MB_OK);
  890. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  891. ReleaseDC(hWnd, hDC);
  892. break;
  893. }
  894. if ((!ffirst) && (!foomonsize))
  895. if (!(hWBitmap = CreateCompatibleBitmap(hDC, xClient,
  896. yClient))) {
  897. foom = 1;
  898. MessageBox(hWnd, "Out of Memory ", szAppName, MB_ICONASTERISK |
  899. MB_OK);
  900. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  901. ReleaseDC(hWnd, hDC);
  902. break;
  903. }
  904. if ((!ffirst) && (!foomonsize))
  905. if (!(hIntDC = CreateCompatibleDC(hDC))) {
  906. foom = 1;
  907. MessageBox(hWnd, "Out of Memory ", szAppName, MB_ICONASTERISK |
  908. MB_OK);
  909. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  910. ReleaseDC(hWnd, hDC);
  911. break;
  912. }
  913. if ((!ffirst) && (!foomonsize))
  914. if (!(hIntBitmap = CreateCompatibleBitmap(hDC, xBlock
  915. *4, yBlock * 4))) {
  916. foom = 1;
  917. MessageBox(hWnd, "Out of Memory ", szAppName, MB_ICONASTERISK |
  918. MB_OK);
  919. PostMessage(hWnd, WM_DESTROY, 0, 0L);
  920. ReleaseDC(hWnd, hDC);
  921. break;
  922. }
  923. if ((!ffirst) && (!foomonsize))
  924. hOldBoardBitmap = SelectObject(hBoardDC, hBoardBitmap);
  925. if ((!ffirst) && (!foomonsize))
  926. hOldIntBitmap = SelectObject(hIntDC, hIntBitmap);
  927. if ((!ffirst) && (!foomonsize))
  928. hOldWBitmap = SelectObject(hMemwinDC, hWBitmap);
  929. foomonsize = 0;
  930. ffirst = 0;
  931. /*
  932. ** We've successfully created all the bitmaps so this size
  933. ** can be done without running out of memory. Therefore, we'll
  934. ** record the current size of the window in case it has to be
  935. ** restored on a subsequent OOM due to a sizing of the window
  936. */
  937. GetWindowRect(hWnd, (LPRECT) & r);
  938. prevxorg = r.left;
  939. prevyorg = r.top;
  940. prevwidth = max(r.right, r.left) - min(r.right, r.left);
  941. prevheight = max(r.bottom, r.top) - min(r.bottom, r.top);
  942. prevwarea = (LONG)LOWORD(lParam) * (LONG)HIWORD(lParam);
  943. ReleaseDC(hWnd, hDC);
  944. break ;
  945. case WM_MOVE:
  946. GetWindowRect(hWnd, (LPRECT) & r);
  947. prevxorg = r.left;
  948. prevyorg = r.top;
  949. break;
  950. case WM_MOUSEACTIVATE:
  951. fmousefocusd = 1;
  952. break;
  953. case WM_ERASEBKGND:
  954. if (fmousefocusd)
  955. fignorelbutton = 1;
  956. break;
  957. case WM_LBUTTONDOWN:
  958. /*If we just got the erasebackground message due to activation via a mouse click, ignore all lbuttondowns until the window is painted */
  959. if (fignorelbutton == 1)
  960. break;
  961. else
  962. fmousefocusd = 0;
  963. hDC = GetDC(hWnd);
  964. xPoint = LOWORD(lParam);
  965. yPoint = HIWORD(lParam);
  966. if (foom == 1) {
  967. MessageBox(hWnd, "Out of Memory", szAppName, MB_ICONASTERISK |
  968. MB_OK);
  969. } else
  970. {
  971. /*If the mouse is clicked in to the left or above or to the right of or below the game board, we have to ignore*/
  972. if (xPoint > winxEdge && yPoint > winyEdge && xPoint
  973. < xBlock * 8 && yPoint < yBlock * 8) {
  974. ixdownblock = (xPoint / xBlock) - 1;
  975. iydownblock = (yPoint / yBlock) - 1;
  976. } else
  977. {
  978. ReleaseDC(hWnd, hDC);
  979. break;
  980. }
  981. /*check to see if the mouse location is on a chip*/
  982. /* if it is on a chip, allow it to be moved*/
  983. if (bState[ixdownblock][iydownblock]) {
  984. if ((ixdownblock > 1 && ixdownblock < 5) || (iydownblock
  985. > 1 && iydownblock < 5)) {
  986. BitBlt(hDC, ixdownblock * xBlock + winxEdge,
  987. iydownblock * yBlock + winyEdge, xBlock, yBlock,
  988. hBoardDC, ixdownblock * xBlock + winxEdge,
  989. iydownblock * yBlock + winyEdge, SRCCOPY);
  990. SelectObject(hMemwinDC, hWBitmap);
  991. BitBlt(hMemwinDC, ixdownblock * xBlock + winxEdge,
  992. iydownblock * yBlock + winyEdge, xBlock, yBlock,
  993. hBoardDC, ixdownblock * xBlock + winxEdge,
  994. iydownblock * yBlock + winyEdge, SRCCOPY);
  995. fmovingchip = 1;
  996. /*Capture all mouse messages */
  997. SetCapture(hWnd);
  998. /*erase the mouse cursor too */
  999. bShow = 0;
  1000. ShowCursor(bShow);
  1001. SelectObject(hIntDC, hIntBitmap);
  1002. BitBlt(hIntDC, 0, 0, xBlock * 4, yBlock * 4,
  1003. hMemwinDC, xPoint - 2 * xBlock, yPoint - 2
  1004. *yBlock, SRCCOPY);
  1005. /* commented out the use of shadow while moving chips
  1006. SelectObject(hIntDC,hMedgrypen);
  1007. SelectObject(hIntDC,hMedgrybrush);
  1008. Ellipse(hIntDC,xBlock+xBlock/2+xEdge+2*xShadow, yBlock+yBlock/2+yEdge+2*yShadow, 2*xBlock+xBlock/2-xEdge+2*xShadow, 2*yBlock+yBlock/2-yEdge+2*yShadow);
  1009. */
  1010. SelectObject(hIntDC, hBlkpen);
  1011. SelectObject(hIntDC, hBbrush);
  1012. Ellipse(hIntDC, xBlock + xBlock / 2 + xEdge,
  1013. yBlock + yBlock / 2 + yEdge, 2 * xBlock +
  1014. xBlock / 2 - xEdge, 2 * yBlock + yBlock / 2
  1015. -yEdge);
  1016. SelectObject(hIntDC, hWpen);
  1017. Arc(hIntDC, xBlock + xBlock / 2 + xEdge + xShadow,
  1018. yBlock + yBlock / 2 + yEdge + yShadow, 2 *
  1019. xBlock + xBlock / 2 - xEdge - xShadow, 2 *
  1020. yBlock + yBlock / 2 - yEdge - yShadow, xBlock
  1021. + xBlock / 2 + xHalf, yBlock + yBlock / 2 +
  1022. yShadow, xBlock + xBlock / 2 + xShadow, yBlock
  1023. + yBlock / 2 + yHalf);
  1024. xPrevpoint = xPoint;
  1025. yPrevpoint = yPoint;
  1026. }
  1027. }
  1028. }
  1029. ReleaseDC(hWnd, hDC);
  1030. break;
  1031. case WM_MOUSEMOVE:
  1032. xPoint = LOWORD(lParam);
  1033. yPoint = HIWORD(lParam);
  1034. if (fmovingchip) {
  1035. if (xPoint > xLeft + xClient || xPoint < xLeft || yPoint
  1036. > yClient + yTop || yPoint < yTop) {
  1037. /* Do what we would do if it wasn't a valid destination . This fixes the problem where moving the mouse outside the window causes us to lose the mouse cursor forever*/
  1038. bShow = 1;
  1039. ShowCursor(bShow);
  1040. fmovingchip = 0;
  1041. ReleaseCapture();
  1042. x = ixdownblock;
  1043. y = iydownblock;
  1044. SelectObject(hMemwinDC, hWBitmap);
  1045. SelectObject(hMemwinDC, hDkgrypen);
  1046. SelectObject(hMemwinDC, hDkgrybrush);
  1047. Ellipse(hMemwinDC, x * xBlock + xEdge + xShadow +
  1048. winxEdge, y * yBlock + yEdge + yShadow + winyEdge,
  1049. (x + 1) * xBlock - xEdge + xShadow + winxEdge,
  1050. (y + 1) * yBlock - yEdge + yShadow + winyEdge);
  1051. SelectObject(hMemwinDC, hBlkpen);
  1052. SelectObject(hMemwinDC, hBbrush);
  1053. Ellipse(hMemwinDC, x * xBlock + xEdge + winxEdge,
  1054. y * yBlock + yEdge + winyEdge, (x + 1) * xBlock -
  1055. xEdge + winxEdge, (y + 1) * yBlock - yEdge + winyEdge);
  1056. SelectObject(hMemwinDC, hWpen);
  1057. Arc(hMemwinDC, x * xBlock + xEdge + xShadow + winxEdge,
  1058. y * yBlock + yEdge + yShadow + winyEdge, (x +
  1059. 1) * xBlock - xEdge - xShadow + winxEdge, (y +
  1060. 1) * yBlock - yEdge - yShadow + winyEdge , x *
  1061. xBlock + xHalf + winxEdge , y * yBlock + yShadow +
  1062. winyEdge, x * xBlock + xShadow + winxEdge, y *
  1063. yBlock + yHalf + winyEdge);
  1064. hDC = GetDC(hWnd);
  1065. BitBlt(hDC, 0, 0, xClient, yClient, hMemwinDC,
  1066. 0, 0, SRCCOPY);
  1067. ReleaseDC(hWnd, hDC);
  1068. }
  1069. }
  1070. /*check if a chip is in a move state */
  1071. if (fmovingchip) {
  1072. /* if it is, bitblt as the mouse moves */
  1073. hDC = GetDC(hWnd);
  1074. /* if we are moving the mouse too fast, we have to erase the old ellipse manually */
  1075. if ((xPrevpoint > xPoint + xBlock) || (xPoint > xPrevpoint
  1076. + xBlock) || (yPrevpoint > yPoint + yBlock) || (yPoint
  1077. > yBlock + yPrevpoint)) {
  1078. SelectObject(hIntDC, hIntBitmap);
  1079. BitBlt(hIntDC, 0, 0, xBlock * 2, yBlock * 2, hMemwinDC,
  1080. xPrevpoint - xBlock, yPrevpoint - yBlock, SRCCOPY);
  1081. BitBlt(hDC, xPrevpoint - xBlock, yPrevpoint - yBlock,
  1082. xBlock * 2, yBlock * 2, hIntDC, 0, 0, SRCCOPY);
  1083. }
  1084. SelectObject(hIntDC, hIntBitmap);
  1085. BitBlt(hIntDC, 0, 0, xBlock * 4, yBlock * 4, hMemwinDC,
  1086. xPoint - 2 * xBlock, yPoint - 2 * yBlock, SRCCOPY);
  1087. /* Commented out shadow while moving *****
  1088. SelectObject(hIntDC,hmedgrypen);
  1089. SelectObject(hIntDC,hMedgrybrush);
  1090. Ellipse(hIntDC,xBlock+xBlock/2+xEdge+2*xShadow, yBlock+yBlock/2+yEdge+2*yShadow, 2*xBlock+xBlock/2-xEdge+2*xShadow, 2*yBlock+yBlock/2-yEdge+2*yShadow);
  1091. */
  1092. SelectObject(hIntDC, hBlkpen);
  1093. SelectObject(hIntDC, hBbrush);
  1094. Ellipse(hIntDC, xBlock + xBlock / 2 + xEdge, yBlock
  1095. + yBlock / 2 + yEdge, 2 * xBlock + xBlock / 2 - xEdge,
  1096. 2 * yBlock + yBlock / 2 - yEdge);
  1097. SelectObject(hIntDC, hWpen);
  1098. Arc(hIntDC, xBlock + xBlock / 2 + xEdge + xShadow,
  1099. yBlock + yBlock / 2 + yEdge + yShadow, 2 * xBlock +
  1100. xBlock / 2 - xEdge - xShadow, 2 * yBlock + yBlock /
  1101. 2 - yEdge - yShadow, xBlock + xBlock / 2 + xHalf, yBlock
  1102. + yBlock / 2 + yShadow, xBlock + xBlock / 2 + xShadow,
  1103. yBlock + yBlock / 2 + yHalf);
  1104. BitBlt(hDC, xPoint - 2 * xBlock, yPoint - 2 * yBlock,
  1105. xBlock * 4, yBlock * 4, hIntDC, 0, 0, SRCCOPY);
  1106. ReleaseDC(hWnd, hDC);
  1107. xPrevpoint = xPoint;
  1108. yPrevpoint = yPoint;
  1109. }
  1110. break ;
  1111. case WM_LBUTTONUP:
  1112. xUp = LOWORD (lParam);
  1113. yUp = HIWORD (lParam);
  1114. /* if we were in a button move state */
  1115. if (fmovingchip) {
  1116. ixupblock = xUp / xBlock - 1;
  1117. iyupblock = yUp / yBlock - 1;
  1118. ReleaseCapture();
  1119. checkfvmove();
  1120. /*and if it was a valid destination */
  1121. if ((!bState[ixupblock][iyupblock]) && (!(ixupblock
  1122. < 2 && iyupblock < 2)) && (!(ixupblock > 4 && iyupblock
  1123. > 4)) && (!(ixupblock < 2 && iyupblock > 4)) && (!(ixupblock
  1124. > 4 && iyupblock < 2)) && fvalidmove && ( xUp > winxEdge) &&
  1125. ( yUp > winyEdge) &&
  1126. ( xUp < xBlock * 8) &&
  1127. ( yUp < yBlock * 8)
  1128. ) {
  1129. /*
  1130. ** adjust the chip in the valid destination rectangle
  1131. ** on the screen and on the memory device context, erase
  1132. ** the chip that was jumped- on the screen and in the
  1133. ** WinMemDC,set fmovingchip to false, and check to see
  1134. ** if there are any more valid moves. If t here aren't,
  1135. ** message and show score
  1136. */
  1137. hDC = GetDC(hWnd);
  1138. /*erase the chip at its current location*/
  1139. BitBlt(hDC, xUp - xBlock / 2 , yUp - yBlock / 2 ,
  1140. xBlock, yBlock, hMemwinDC, xUp - xBlock / 2 ,
  1141. yUp - yBlock / 2 , SRCCOPY);
  1142. /*center the chip at the new destination */
  1143. x = ixupblock;
  1144. y = iyupblock;
  1145. /* Draw the peg at its new location */
  1146. SelectObject(hDC, hDkgrypen);
  1147. SelectObject(hDC, hDkgrybrush);
  1148. Ellipse(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  1149. y * yBlock + yEdge + yShadow + winyEdge, (x +
  1150. 1) * xBlock - xEdge + xShadow + winxEdge, (y +
  1151. 1) * yBlock - yEdge + yShadow + winyEdge);
  1152. SelectObject(hDC, hBlkpen);
  1153. SelectObject(hDC, hBbrush);
  1154. Ellipse(hDC, x * xBlock + xEdge + winxEdge, y *
  1155. yBlock + yEdge + winyEdge, (x + 1) * xBlock - xEdge +
  1156. winxEdge, (y + 1) * yBlock - yEdge + winyEdge);
  1157. SelectObject(hDC, hWpen);
  1158. Arc(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  1159. y * yBlock + yEdge + yShadow + winyEdge, (x +
  1160. 1) * xBlock - xEdge - xShadow + winxEdge, (y +
  1161. 1) * yBlock - yEdge - yShadow + winyEdge , x *
  1162. xBlock + xHalf + winxEdge , y * yBlock + yShadow +
  1163. winyEdge, x * xBlock + xShadow + winxEdge, y *
  1164. yBlock + yHalf + winyEdge);
  1165. /*erase the jumped chip */
  1166. BitBlt(hDC, xBlock * ixkilledblock + winxEdge,
  1167. yBlock * iykilledblock + winyEdge, xBlock, yBlock,
  1168. hBoardDC, xBlock * ixkilledblock + winxEdge, yBlock
  1169. *iykilledblock + winyEdge , SRCCOPY);
  1170. ReleaseDC(hWnd, hDC);
  1171. /*center the chip in the memory dc as well*/
  1172. #ifdef OLDWAY
  1173. SelectObject(hMemwinDC, hWBitmap);
  1174. BitBlt(hMemwinDC, xBlock * ixupblock + winxEdge,
  1175. yBlock * iyupblock + winyEdge, xBlock, yBlock,
  1176. hDC, xBlock * ixupblock + winxEdge, yBlock * iyupblock +
  1177. winyEdge , SRCCOPY);
  1178. #endif
  1179. /* Draw the peg at its new location in the memory DC*/
  1180. SelectObject(hMemwinDC, hDkgrypen);
  1181. SelectObject(hMemwinDC, hDkgrybrush);
  1182. Ellipse(hMemwinDC, x * xBlock + xEdge + xShadow + winxEdge,
  1183. y * yBlock + yEdge + yShadow + winyEdge, (x +
  1184. 1) * xBlock - xEdge + xShadow + winxEdge, (y +
  1185. 1) * yBlock - yEdge + yShadow + winyEdge);
  1186. SelectObject(hMemwinDC, hBlkpen);
  1187. SelectObject(hMemwinDC, hBbrush);
  1188. Ellipse(hMemwinDC, x * xBlock + xEdge + winxEdge, y *
  1189. yBlock + yEdge + winyEdge, (x + 1) * xBlock - xEdge +
  1190. winxEdge, (y + 1) * yBlock - yEdge + winyEdge);
  1191. SelectObject(hMemwinDC, hWpen);
  1192. Arc(hMemwinDC, x * xBlock + xEdge + xShadow + winxEdge,
  1193. y * yBlock + yEdge + yShadow + winyEdge, (x +
  1194. 1) * xBlock - xEdge - xShadow + winxEdge, (y +
  1195. 1) * yBlock - yEdge - yShadow + winyEdge , x *
  1196. xBlock + xHalf + winxEdge , y * yBlock + yShadow +
  1197. winyEdge, x * xBlock + xShadow + winxEdge, y *
  1198. yBlock + yHalf + winyEdge);
  1199. /*erase the jumped chip in memory DC*/
  1200. BitBlt(hMemwinDC, xBlock * ixkilledblock + winxEdge,
  1201. yBlock * iykilledblock + winyEdge, xBlock, yBlock,
  1202. hBoardDC, xBlock * ixkilledblock + winxEdge, yBlock
  1203. *iykilledblock + winyEdge , SRCCOPY);
  1204. /*update the data structure */
  1205. bState[ixdownblock][iydownblock] = 0;
  1206. bState[ixupblock][iyupblock] = 1;
  1207. bState[ixkilledblock][iykilledblock] = 0;
  1208. /*record move in array list */
  1209. move[m].xsource = ixdownblock;
  1210. move[m].ysource = iydownblock;
  1211. move[m].xdest = ixupblock;
  1212. move[m].ydest = iyupblock;
  1213. move[m].xjumped = ixkilledblock;
  1214. move[m].yjumped = iykilledblock;
  1215. ++m;
  1216. /*
  1217. ixvdownblock=ixdownblock;
  1218. ixvupblock=ixupblock;
  1219. ixvkilledblock=ixkilledblock;
  1220. */
  1221. /* Check if there are anymore valid moves*/
  1222. bShow = 1;
  1223. ShowCursor(bShow);
  1224. fanymoremoves = 0;
  1225. checkfanymoves();
  1226. if (fanymoremoves == 0) {/* if there aren't - declare game at an end and score */
  1227. /*add up the remaining chips*/
  1228. ntotal = 0;
  1229. for (j = 0; j < 7; ++j)
  1230. for (k = 0; k < 7; ++k)
  1231. ntotal += bState[j][k];
  1232. if (ntotal > 1)
  1233. MessageBox(hWnd, "Game Over", szAppName,
  1234. MB_ICONASTERISK | MB_OK);
  1235. else
  1236. MessageBox(hWnd, "You Win!", szAppName,
  1237. MB_ICONASTERISK | MB_OK);
  1238. }
  1239. }
  1240. else /*it wasn't a valid destination */ {
  1241. /*put a chip back in the original location */
  1242. hDC = GetDC(hWnd);
  1243. /*erase the current chip on screen*/
  1244. BitBlt(hDC, xUp - xBlock / 2 , yUp - yBlock / 2 ,
  1245. xBlock, yBlock, hMemwinDC, xUp - xBlock / 2 ,
  1246. yUp - yBlock / 2 , SRCCOPY);
  1247. /*Draw the chip back at the original location*/
  1248. x = ixdownblock;
  1249. y = iydownblock;
  1250. SelectObject(hDC, hDkgrypen);
  1251. SelectObject(hDC, hDkgrybrush);
  1252. Ellipse(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  1253. y * yBlock + yEdge + yShadow + winyEdge, (x +
  1254. 1) * xBlock - xEdge + xShadow + winxEdge, (y +
  1255. 1) * yBlock - yEdge + yShadow + winyEdge);
  1256. SelectObject(hDC, hBlkpen);
  1257. SelectObject(hDC, hBbrush);
  1258. Ellipse(hDC, x * xBlock + xEdge + winxEdge, y *
  1259. yBlock + yEdge + winyEdge, (x + 1) * xBlock - xEdge +
  1260. winxEdge, (y + 1) * yBlock - yEdge + winyEdge);
  1261. SelectObject(hDC, hWpen);
  1262. Arc(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  1263. y * yBlock + yEdge + yShadow + winyEdge, (x +
  1264. 1) * xBlock - xEdge - xShadow + winxEdge, (y +
  1265. 1) * yBlock - yEdge - yShadow + winyEdge , x *
  1266. xBlock + xHalf + winxEdge , y * yBlock + yShadow +
  1267. winyEdge, x * xBlock + xShadow + winxEdge, y *
  1268. yBlock + yHalf + winyEdge);
  1269. SelectObject(hMemwinDC, hWBitmap);
  1270. BitBlt(hMemwinDC, ixdownblock * xBlock + winxEdge,
  1271. iydownblock * yBlock + winyEdge, xBlock, yBlock,
  1272. hDC, ixdownblock * xBlock + winxEdge, iydownblock
  1273. *yBlock + winyEdge , SRCCOPY);
  1274. bShow = 1;
  1275. ShowCursor(bShow);
  1276. ReleaseDC(hWnd, hDC);
  1277. }
  1278. fmovingchip = 0;
  1279. fvalidmove = 0;
  1280. }
  1281. /*
  1282. ** if we aren't at a valid destination, take the chip back to
  1283. ** the original rectangle in the window DC, restore the original
  1284. ** whole-window-Mem-DC as well,and restore the destination area,
  1285. ** and show an error message, and set fmovingchip to false
  1286. */
  1287. break;
  1288. case WM_PAINT:
  1289. hDC = BeginPaint (hWnd, &ps);
  1290. /*Draw the board with holes in it in memory*/
  1291. SelectObject(hDC, hLtgrypen);
  1292. SelectObject(hDC, hLtgrybrush);
  1293. Rectangle(hDC, 0, 0, xClient, yClient);
  1294. SelectObject(hMemwinDC, hWBitmap);
  1295. SelectObject(hMemwinDC, hBlkpen);
  1296. SelectObject(hMemwinDC, hLtgrybrush);
  1297. Rectangle(hMemwinDC, 0, 0, xClient, yClient);
  1298. /*Draw shadows on playing board on right and bottom edges*/
  1299. SelectObject(hMemwinDC, hThkdkgrypen);
  1300. (VOID)MMoveTo(hMemwinDC, winxEdge + 1, yBlock * 5 + winyEdge
  1301. + 1);
  1302. LineTo(hMemwinDC, xBlock * 2 + winxEdge - 1, yBlock * 5 +
  1303. winyEdge + 1);
  1304. (VOID)MMoveTo(hMemwinDC, xBlock * 2 + winxEdge, yBlock
  1305. *7 + winyEdge + 1);
  1306. LineTo(hMemwinDC, xBlock * 5 + winxEdge, yBlock * 7 + winyEdge
  1307. + 1);
  1308. (VOID)MMoveTo(hMemwinDC, xBlock * 5 + winxEdge + 1, yBlock
  1309. *7 + winyEdge + 1);
  1310. LineTo(hMemwinDC, xBlock * 5 + winxEdge + 1, yBlock * 5 +
  1311. winyEdge + 1);
  1312. (VOID)MMoveTo(hMemwinDC, xBlock * 5 + winxEdge + 1, yBlock
  1313. *5 + winyEdge + 1);
  1314. LineTo(hMemwinDC, xBlock * 7 + winxEdge + 1, yBlock * 5 +
  1315. winyEdge + 1);
  1316. (VOID)MMoveTo(hMemwinDC, xBlock * 5 + winxEdge + 1, yBlock
  1317. *2 + winyEdge - 1);
  1318. LineTo(hMemwinDC, xBlock * 5 + winxEdge + 1, winyEdge);
  1319. (VOID)MMoveTo(hMemwinDC, xBlock * 7 + winxEdge + 1, yBlock
  1320. *2 + winyEdge + 1);
  1321. LineTo(hMemwinDC, xBlock * 7 + winxEdge + 1, yBlock * 5 +
  1322. winyEdge + 1);
  1323. SelectObject(hMemwinDC, hWpen);
  1324. (VOID)MMoveTo(hMemwinDC, winxEdge - 1, yBlock * 2 + winyEdge);
  1325. LineTo(hMemwinDC, winxEdge - 1, yBlock * 5 + winyEdge -
  1326. 1);
  1327. (VOID)MMoveTo(hMemwinDC, winxEdge, yBlock * 2 - 1 + winyEdge);
  1328. LineTo(hMemwinDC, xBlock * 2 - 1 + winxEdge, yBlock * 2
  1329. -1 + winyEdge);
  1330. (VOID)MMoveTo(hMemwinDC, xBlock * 2 - 1 + winxEdge, yBlock
  1331. *2 + winyEdge - 1);
  1332. LineTo(hMemwinDC, xBlock * 2 - 1 + winxEdge, yBlock * 0 +
  1333. winyEdge);
  1334. (VOID)MMoveTo(hMemwinDC, xBlock * 2 + winxEdge, winyEdge -
  1335. 1);
  1336. LineTo(hMemwinDC, xBlock * 5 - 1 + winxEdge, winyEdge -
  1337. 1);
  1338. (VOID)MMoveTo(hMemwinDC, xBlock * 5 + 2 + winxEdge, yBlock
  1339. *2 - 1 + winyEdge);
  1340. LineTo(hMemwinDC, xBlock * 7 + winxEdge, yBlock * 2 - 1 +
  1341. winyEdge);
  1342. (VOID)MMoveTo(hMemwinDC, xBlock * 2 - 1 + winxEdge, yBlock
  1343. *5 + 1 + winyEdge);
  1344. LineTo(hMemwinDC, xBlock * 2 - 1 + winxEdge, yBlock * 7 -
  1345. 1 + winyEdge);
  1346. /* Draw the holes*/
  1347. SelectObject(hMemwinDC, hBlkpen);
  1348. for (x = 0; x < DIVISIONS; x++)
  1349. for (y = 0; y < DIVISIONS; y++) {
  1350. if ((x > 1 && x < 5) || (y > 1 && y < 5)) {
  1351. Arc(hMemwinDC, x * xBlock + xEdge + winxEdge,
  1352. y * yBlock + yEdge + winyEdge, (x + 1) * xBlock
  1353. -xEdge + winxEdge, (y + 1) * yBlock - yEdge +
  1354. winyEdge, (x + 1) * xBlock - 3 * xEdge / 2 +
  1355. winxEdge, y * yBlock + 3 * yEdge / 2 + winyEdge,
  1356. x * xBlock + 3 * xEdge / 2 + winxEdge, (y
  1357. + 1) * yBlock - 3 * yEdge / 2 + winyEdge);
  1358. }
  1359. }
  1360. SelectObject(hMemwinDC, hLtwpen);
  1361. for (x = 0; x < DIVISIONS; x++)
  1362. for (y = 0; y < DIVISIONS; y++) {
  1363. if ((x > 1 && x < 5) || (y > 1 && y < 5)) {
  1364. Arc(hMemwinDC, x * xBlock + xEdge + winxEdge,
  1365. y * yBlock + yEdge + winyEdge, (x + 1) * xBlock
  1366. -xEdge + winxEdge, (y + 1) * yBlock - yEdge +
  1367. winyEdge, x * xBlock + 3 * xEdge / 2 + winxEdge,
  1368. (y + 1) * yBlock - 3 * yEdge / 2 + winyEdge,
  1369. (x + 1) * xBlock - 3 * xEdge / 2 + winxEdge,
  1370. y * yBlock + 3 * yEdge / 2 + winyEdge);
  1371. }
  1372. }
  1373. BitBlt(hDC, 0, 0, xClient, yClient, hMemwinDC , 0, 0, SRCCOPY);
  1374. /*Get a picture of an empty board*/
  1375. SelectObject(hBoardDC, hBoardBitmap);
  1376. BitBlt(hBoardDC, 0, 0, xClient, yClient, hMemwinDC , 0,
  1377. 0, SRCCOPY);
  1378. for (x = 0; x < DIVISIONS; x++)
  1379. for (y = 0; y < DIVISIONS; y++) {
  1380. if (bState[x][y]) {
  1381. SelectObject(hDC, hDkgrypen);
  1382. SelectObject(hDC, hDkgrybrush);
  1383. Ellipse(hDC, x * xBlock + xEdge + xShadow +
  1384. winxEdge, y * yBlock + yEdge + yShadow + winyEdge,
  1385. (x + 1) * xBlock - xEdge + xShadow + winxEdge,
  1386. (y + 1) * yBlock - yEdge + yShadow + winyEdge);
  1387. SelectObject(hDC, hBlkpen);
  1388. SelectObject(hDC, hBbrush);
  1389. Ellipse(hDC, x * xBlock + xEdge + winxEdge,
  1390. y * yBlock + yEdge + winyEdge, (x + 1) * xBlock -
  1391. xEdge + winxEdge, (y + 1) * yBlock - yEdge +
  1392. winyEdge);
  1393. SelectObject(hDC, hWpen);
  1394. Arc(hDC, x * xBlock + xEdge + xShadow + winxEdge,
  1395. y * yBlock + yEdge + yShadow + winyEdge, (x
  1396. + 1) * xBlock - xEdge - xShadow + winxEdge,
  1397. (y + 1) * yBlock - yEdge - yShadow + winyEdge ,
  1398. x * xBlock + xHalf + winxEdge , y * yBlock +
  1399. yShadow + winyEdge, x * xBlock + xShadow +
  1400. winxEdge, y * yBlock + yHalf + winyEdge);
  1401. }
  1402. }
  1403. BitBlt(hMemwinDC, 0, 0, xClient, yClient, hDC, 0, 0, SRCCOPY);
  1404. EndPaint(hWnd, &ps);
  1405. fignorelbutton = 0;
  1406. fmousefocusd = 0;
  1407. if (foomed) {
  1408. MessageBox(hWnd, "Not Enough Memory to Re-size Window",
  1409. szAppName, MB_ICONASTERISK | MB_OK);
  1410. foomed = 0;
  1411. }
  1412. break;
  1413. case WM_DESTROY:
  1414. if (hBitmap)
  1415. DeleteObject (hBitmap) ;
  1416. KillTimer (hWnd, 1) ;
  1417. SelectObject(hIntDC, hOldIntBitmap);
  1418. DeleteDC(hIntDC);
  1419. SelectObject(hMemwinDC, hOldWBitmap);
  1420. DeleteDC(hMemwinDC);
  1421. SelectObject(hBoardDC, hOldBoardBitmap);
  1422. DeleteDC(hBoardDC);
  1423. DeleteObject(hBoardBitmap);
  1424. DeleteObject(hOldBoardBitmap);
  1425. DeleteObject(hWBitmap);
  1426. DeleteObject(hOldWBitmap);
  1427. DeleteObject(hIntBitmap);
  1428. DeleteObject(hOldIntBitmap);
  1429. DeleteObject(hBbrush);
  1430. DeleteObject(hBlkpen);
  1431. DeleteObject(hBlkbrush);
  1432. DeleteObject(hDkgrybrush);
  1433. DeleteObject(hDkgrypen);
  1434. DeleteObject(hGbrush);
  1435. DeleteObject(hMedgrypen);
  1436. DeleteObject(hMedgrybrush);
  1437. DeleteObject(hLtgrybrush);
  1438. DeleteObject(hLtgrypen);
  1439. DeleteObject(hLtwpen);
  1440. DeleteObject(hThkdkgrypen);
  1441. DeleteObject(hWpen);
  1442. DeleteObject(hYbrush);
  1443. WinHelp(hWnd, HELP_FILE, HELP_QUIT, (ULONG_PTR) NULL);
  1444. switch (wprevmenuitem) {
  1445. case 3:
  1446. WritePrivateProfileString((LPSTR)"Pegged", (LPSTR) "Option",
  1447. (LPSTR)"3", (LPSTR)"entpack.ini" );
  1448. break;
  1449. case 4:
  1450. WritePrivateProfileString( (LPSTR)"Pegged", (LPSTR)"Option",
  1451. (LPSTR) "4", (LPSTR)"entpack.ini" );
  1452. break;
  1453. case 5:
  1454. WritePrivateProfileString((LPSTR)"Pegged", (LPSTR)"Option",
  1455. (LPSTR)"5", (LPSTR)"entpack.ini" );
  1456. break;
  1457. case 6:
  1458. WritePrivateProfileString((LPSTR)"Pegged", (LPSTR)"Option",
  1459. (LPSTR)"6", (LPSTR)"entpack.ini" );
  1460. break;
  1461. case 7:
  1462. WritePrivateProfileString((LPSTR)"Pegged", (LPSTR)"Option",
  1463. (LPSTR)"7", (LPSTR)"entpack.ini");
  1464. break;
  1465. case 8:
  1466. WritePrivateProfileString((LPSTR)"Pegged", (LPSTR)"Option",
  1467. (LPSTR)"8", (LPSTR)"entpack.ini");
  1468. break;
  1469. case 9:
  1470. WritePrivateProfileString((LPSTR)"Pegged", (LPSTR)"Option",
  1471. (LPSTR)"9", (LPSTR)"entpack.ini");
  1472. break;
  1473. default:
  1474. WritePrivateProfileString((LPSTR)"Pegged", (LPSTR)"Option",
  1475. (LPSTR)"3", (LPSTR)"entpack.ini" );
  1476. break;
  1477. }
  1478. PostQuitMessage (0) ;
  1479. break ;
  1480. default:
  1481. return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  1482. }
  1483. return 0L ;
  1484. }
  1485. VOID checkfvmove()
  1486. {
  1487. if (ixupblock == ixdownblock)
  1488. if ((iyupblock == iydownblock - 2) || (iyupblock == iydownblock +
  1489. 2)) {
  1490. ixjumpedblock = ixupblock;
  1491. if (iyupblock == iydownblock - 2)
  1492. iyjumpedblock = iydownblock - 1;
  1493. if (iyupblock == iydownblock + 2)
  1494. iyjumpedblock = iydownblock + 1;
  1495. if (bState[ixjumpedblock][iyjumpedblock]) {
  1496. fvalidmove = 1;
  1497. ixkilledblock = ixupblock;
  1498. if (iyupblock == iydownblock - 2)
  1499. iykilledblock = iydownblock - 1;
  1500. if (iyupblock == iydownblock + 2)
  1501. iykilledblock = iydownblock + 1;
  1502. }
  1503. }
  1504. if (iyupblock == iydownblock)
  1505. if ((ixupblock == ixdownblock - 2) || (ixupblock == ixdownblock +
  1506. 2)) {
  1507. iyjumpedblock = iyupblock;
  1508. if (ixupblock == ixdownblock - 2)
  1509. ixjumpedblock = ixdownblock - 1;
  1510. if (ixupblock == ixdownblock + 2)
  1511. ixjumpedblock = ixdownblock + 1;
  1512. if (bState[ixjumpedblock][iyjumpedblock]) {
  1513. fvalidmove = 1;
  1514. iykilledblock = iyupblock;
  1515. if (ixupblock == ixdownblock - 2)
  1516. ixkilledblock = ixdownblock - 1;
  1517. if (ixupblock == ixdownblock + 2)
  1518. ixkilledblock = ixdownblock + 1;
  1519. }
  1520. }
  1521. return;
  1522. }
  1523. VOID checkfanymoves()
  1524. {
  1525. /*corners*/
  1526. if (bState[2][0]) {
  1527. if (bState[3][0])
  1528. if (!bState[4][0])
  1529. fanymoremoves = 1;
  1530. if (bState[2][1])
  1531. if (!bState[2][2])
  1532. fanymoremoves = 1;
  1533. }
  1534. if (bState[4][0]) {
  1535. if (bState[3][0])
  1536. if (!bState[2][0])
  1537. fanymoremoves = 1;
  1538. if (bState[4][1])
  1539. if (!bState[4][2])
  1540. fanymoremoves = 1;
  1541. }
  1542. if (bState[0][2]) {
  1543. if (bState[1][2])
  1544. if (!bState[2][2])
  1545. fanymoremoves = 1;
  1546. if (bState[0][3])
  1547. if (!bState[0][4])
  1548. fanymoremoves = 1;
  1549. }
  1550. if (bState[0][4]) {
  1551. if (bState[0][3])
  1552. if (!bState[0][2])
  1553. fanymoremoves = 1;
  1554. if (bState[1][4])
  1555. if (!bState[2][4])
  1556. fanymoremoves = 1;
  1557. }
  1558. if (bState[2][6]) {
  1559. if (bState[3][6])
  1560. if (!bState[4][6])
  1561. fanymoremoves = 1;
  1562. if (bState[2][5])
  1563. if (!bState[2][4])
  1564. fanymoremoves = 1;
  1565. }
  1566. if (bState[4][6]) {
  1567. if (bState[3][6])
  1568. if (!bState[2][6])
  1569. fanymoremoves = 1;
  1570. if (bState[4][5])
  1571. if (!bState[4][4])
  1572. fanymoremoves = 1;
  1573. }
  1574. if (bState[6][4]) {
  1575. if (bState[5][4])
  1576. if (!bState[4][4])
  1577. fanymoremoves = 1;
  1578. if (bState[6][3])
  1579. if (!bState[6][2])
  1580. fanymoremoves = 1;
  1581. }
  1582. if (bState[6][2]) {
  1583. if (bState[5][2])
  1584. if (!bState[4][2])
  1585. fanymoremoves = 1;
  1586. if (bState[6][3])
  1587. if (!bState[6][4])
  1588. fanymoremoves = 1;
  1589. }
  1590. /* center ends */
  1591. if (bState[3][0]) {
  1592. if (bState[3][1])
  1593. if (!bState[3][2])
  1594. fanymoremoves = 1;
  1595. }
  1596. if (bState[0][3]) {
  1597. if (bState[1][3])
  1598. if (!bState[2][3])
  1599. fanymoremoves = 1;
  1600. }
  1601. if (bState[3][6]) {
  1602. if (bState[3][5])
  1603. if (!bState[3][4])
  1604. fanymoremoves = 1;
  1605. }
  1606. if (bState[6][3]) {
  1607. if (bState[5][3])
  1608. if (!bState[4][3])
  1609. fanymoremoves = 1;
  1610. }
  1611. /*center sides */
  1612. if (bState[2][1]) {
  1613. if (bState[3][1])
  1614. if (!bState[4][1])
  1615. fanymoremoves = 1;
  1616. if (bState[2][2])
  1617. if (!bState[2][3])
  1618. fanymoremoves = 1;
  1619. }
  1620. if (bState[1][2]) {
  1621. if (bState[2][2])
  1622. if (!bState[3][2])
  1623. fanymoremoves = 1;
  1624. if (bState[1][3])
  1625. if (!bState[1][4])
  1626. fanymoremoves = 1;
  1627. }
  1628. if (bState[1][4]) {
  1629. if (bState[2][4])
  1630. if (!bState[3][4])
  1631. fanymoremoves = 1;
  1632. if (bState[1][3])
  1633. if (!bState[1][2])
  1634. fanymoremoves = 1;
  1635. }
  1636. if (bState[2][5]) {
  1637. if (bState[3][5])
  1638. if (!bState[4][5])
  1639. fanymoremoves = 1;
  1640. if (bState[2][4])
  1641. if (!bState[2][3])
  1642. fanymoremoves = 1;
  1643. }
  1644. if (bState[4][5]) {
  1645. if (bState[3][5])
  1646. if (!bState[2][5])
  1647. fanymoremoves = 1;
  1648. if (bState[4][4])
  1649. if (!bState[4][3])
  1650. fanymoremoves = 1;
  1651. }
  1652. if (bState[5][4]) {
  1653. if (bState[4][4])
  1654. if (!bState[3][4])
  1655. fanymoremoves = 1;
  1656. if (bState[5][3])
  1657. if (!bState[5][2])
  1658. fanymoremoves = 1;
  1659. }
  1660. if (bState[5][2]) {
  1661. if (bState[4][2])
  1662. if (!bState[3][2])
  1663. fanymoremoves = 1;
  1664. if (bState[5][3])
  1665. if (!bState[5][4])
  1666. fanymoremoves = 1;
  1667. }
  1668. if (bState[4][1]) {
  1669. if (bState[3][1])
  1670. if (!bState[2][1])
  1671. fanymoremoves = 1;
  1672. if (bState[4][2])
  1673. if (!bState[4][3])
  1674. fanymoremoves = 1;
  1675. }
  1676. /* inside center arms */
  1677. if (bState[3][1]) {
  1678. if (bState[3][2])
  1679. if (!bState[3][3])
  1680. fanymoremoves = 1;
  1681. }
  1682. if (bState[1][3]) {
  1683. if (bState[2][3])
  1684. if (!bState[3][3])
  1685. fanymoremoves = 1;
  1686. }
  1687. if (bState[3][5]) {
  1688. if (bState[3][4])
  1689. if (!bState[3][3])
  1690. fanymoremoves = 1;
  1691. }
  1692. if (bState[5][3]) {
  1693. if (bState[4][3])
  1694. if (!bState[3][3])
  1695. fanymoremoves = 1;
  1696. }
  1697. /*Center 9 squares */
  1698. if (bState[2][2]) {
  1699. if (bState[1][2])
  1700. if (!bState[0][2])
  1701. fanymoremoves = 1;
  1702. if (bState[3][2])
  1703. if (!bState[4][2])
  1704. fanymoremoves = 1;
  1705. if (bState[2][1])
  1706. if (!bState[2][0])
  1707. fanymoremoves = 1;
  1708. if (bState[2][3])
  1709. if (!bState[2][4])
  1710. fanymoremoves = 1;
  1711. }
  1712. if (bState[3][2]) {
  1713. if (bState[2][2])
  1714. if (!bState[2][1])
  1715. fanymoremoves = 1;
  1716. if (bState[4][2])
  1717. if (!bState[5][2])
  1718. fanymoremoves = 1;
  1719. if (bState[3][1])
  1720. if (!bState[3][0])
  1721. fanymoremoves = 1;
  1722. if (bState[3][3])
  1723. if (!bState[3][4])
  1724. fanymoremoves = 1;
  1725. }
  1726. if (bState[4][2]) {
  1727. if (bState[3][2])
  1728. if (!bState[2][2])
  1729. fanymoremoves = 1;
  1730. if (bState[5][2])
  1731. if (!bState[6][2])
  1732. fanymoremoves = 1;
  1733. if (bState[4][1])
  1734. if (!bState[4][0])
  1735. fanymoremoves = 1;
  1736. if (bState[4][3])
  1737. if (!bState[4][4])
  1738. fanymoremoves = 1;
  1739. }
  1740. if (bState[2][3]) {
  1741. if (bState[1][3])
  1742. if (!bState[0][3])
  1743. fanymoremoves = 1;
  1744. if (bState[3][3])
  1745. if (!bState[4][3])
  1746. fanymoremoves = 1;
  1747. if (bState[2][2])
  1748. if (!bState[2][1])
  1749. fanymoremoves = 1;
  1750. if (bState[2][4])
  1751. if (!bState[2][5])
  1752. fanymoremoves = 1;
  1753. }
  1754. if (bState[2][4]) {
  1755. if (bState[1][4])
  1756. if (!bState[0][4])
  1757. fanymoremoves = 1;
  1758. if (bState[3][4])
  1759. if (!bState[4][4])
  1760. fanymoremoves = 1;
  1761. if (bState[2][3])
  1762. if (!bState[2][2])
  1763. fanymoremoves = 1;
  1764. if (bState[2][5])
  1765. if (!bState[2][6])
  1766. fanymoremoves = 1;
  1767. }
  1768. if (bState[3][4]) {
  1769. if (bState[2][4])
  1770. if (!bState[1][4])
  1771. fanymoremoves = 1;
  1772. if (bState[4][4])
  1773. if (!bState[5][4])
  1774. fanymoremoves = 1;
  1775. if (bState[3][3])
  1776. if (!bState[3][2])
  1777. fanymoremoves = 1;
  1778. if (bState[3][5])
  1779. if (!bState[3][6])
  1780. fanymoremoves = 1;
  1781. }
  1782. if (bState[4][4]) {
  1783. if (bState[3][4])
  1784. if (!bState[2][4])
  1785. fanymoremoves = 1;
  1786. if (bState[5][4])
  1787. if (!bState[6][4])
  1788. fanymoremoves = 1;
  1789. if (bState[4][3])
  1790. if (!bState[4][2])
  1791. fanymoremoves = 1;
  1792. if (bState[4][5])
  1793. if (!bState[4][6])
  1794. fanymoremoves = 1;
  1795. }
  1796. if (bState[4][3]) {
  1797. if (bState[3][3])
  1798. if (!bState[2][3])
  1799. fanymoremoves = 1;
  1800. if (bState[5][3])
  1801. if (!bState[6][3])
  1802. fanymoremoves = 1;
  1803. if (bState[4][2])
  1804. if (!bState[4][1])
  1805. fanymoremoves = 1;
  1806. if (bState[4][4])
  1807. if (!bState[4][5])
  1808. fanymoremoves = 1;
  1809. }
  1810. if (bState[3][3]) {
  1811. if (bState[2][3])
  1812. if (!bState[1][3])
  1813. fanymoremoves = 1;
  1814. if (bState[4][3])
  1815. if (!bState[5][3])
  1816. fanymoremoves = 1;
  1817. if (bState[3][2])
  1818. if (!bState[3][1])
  1819. fanymoremoves = 1;
  1820. if (bState[3][4])
  1821. if (!bState[3][5])
  1822. fanymoremoves = 1;
  1823. }
  1824. }
  1825.