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.

1582 lines
45 KiB

  1. /****************************************************************************/
  2. /* */
  3. /* Windows Reversi - */
  4. /* */
  5. /* Originally written by Chris Peters */
  6. /* */
  7. /****************************************************************************/
  8. #include <stddef.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <objbase.h>
  12. #include <windows.h>
  13. #include <math.h>
  14. #include <float.h>
  15. #include "windows.h"
  16. #include <port1632.h>
  17. #include <process.h>
  18. #include <stdlib.h>
  19. #include "reversi.h"
  20. #include <gdiplus.h>
  21. using namespace Gdiplus;
  22. /* Exported procedures called from other modules */
  23. LRESULT APIENTRY ReversiWndProc(HWND, UINT, WPARAM, LPARAM);
  24. VOID APIENTRY InverseMessage(HWND, UINT, UINT_PTR, DWORD);
  25. INT_PTR APIENTRY AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
  26. PWSTR pDisplayMessage;
  27. Brush *brBlack;
  28. Brush *brPat;
  29. Brush *brWhite;
  30. Brush *brRed;
  31. Brush *brGreen;
  32. Brush *brBlue;
  33. Brush *brHuman;
  34. Brush *brComputer;
  35. HBRUSH hbrWhite;
  36. HBRUSH hbrGreen;
  37. HANDLE hInst;
  38. HANDLE curIllegal;
  39. HANDLE curLegal;
  40. HANDLE curThink;
  41. HANDLE curBlank;
  42. BOOL fThinking = FALSE;
  43. BOOL fCheated = FALSE;
  44. INT direc[9] = {9, 10, 11, 1, -1, -9, -10, -11, 0};
  45. WORD prevCheck;
  46. BYTE board[max_depth+2][BoardSize];
  47. INT fPass;
  48. INT flashtimes;
  49. INT count;
  50. INT MessageOn;
  51. INT charheight;
  52. INT charwidth;
  53. INT xscr;
  54. WCHAR strBuf[80];
  55. BOOL bMouseDownInReversi = FALSE;
  56. INT xExt;
  57. INT yExt;
  58. INT Bx;
  59. INT By;
  60. INT ASPECT;
  61. INT COLOR;
  62. INT TXMIN;
  63. INT TYMIN = 45;
  64. INT dimension;
  65. BOOL ffirstmove;
  66. WCHAR szReversi[20];
  67. WCHAR szReversiPractice[40];
  68. WCHAR szPass[30];
  69. WCHAR szMustPass[30];
  70. WCHAR szTie[30];
  71. WCHAR szLoss[30];
  72. WCHAR szWon[30];
  73. WCHAR szWonPost[30];
  74. WCHAR szLossPost[30];
  75. WCHAR szAbout[20];
  76. WCHAR szIllegal[70];
  77. WCHAR szNoPass[70];
  78. WCHAR szHelpFile[15];
  79. HANDLE hAccel;
  80. POINT MousePos;
  81. INT depth;
  82. INT BestMove[max_depth+2];
  83. HDC hDisp;
  84. HWND hWin;
  85. Graphics *g;
  86. INT moves[61] = {11,18,81,88, 13,31,16,61,
  87. 38,83,68,86, 14,41,15,51,
  88. 48,84,58,85, 33,36,63,66,
  89. 34,35,43,46, 53,56,64,65,
  90. 24,25,42,47, 52,57,74,75,
  91. 23,26,32,37, 62,67,73,76,
  92. 12,17,21,28, 71,78,82,87,
  93. 22,27,72,77,
  94. 0};
  95. INT NEAR PASCAL minmax(BYTE b[max_depth + 2][100], INT move, INT friendly,
  96. INT enemy, INT ply, INT vmin, INT vmax);
  97. VOID NEAR PASCAL makemove(BYTE b[], INT move, INT friendly, INT enemy);
  98. INT NEAR PASCAL legalcheck(BYTE b[], INT move, INT friendly, INT enemy);
  99. /*--------------------------------------------------------------------------*/
  100. /* */
  101. /* UpdateCursor() - */
  102. /* */
  103. /*--------------------------------------------------------------------------*/
  104. /* To use UpdateCursor, set the global var MousePos.x and MousePos.y and make
  105. * the call. The cursor will appear at the new position
  106. */
  107. VOID NEAR PASCAL UpdateCursor(
  108. HWND hwnd)
  109. {
  110. POINT curpoint;
  111. curpoint.x = MousePos.x;
  112. curpoint.y = MousePos.y;
  113. ClientToScreen(hwnd, (LPPOINT)&curpoint);
  114. SetCursorPos(curpoint.x, curpoint.y);
  115. }
  116. /*--------------------------------------------------------------------------*/
  117. /* */
  118. /* checkdepth() - */
  119. /* */
  120. /*--------------------------------------------------------------------------*/
  121. VOID NEAR PASCAL checkdepth(
  122. HWND hWindow,
  123. WORD d)
  124. {
  125. HMENU hMenu;
  126. hMenu = GetMenu(hWindow);
  127. CheckMenuItem(hMenu, prevCheck, MF_UNCHECKED);
  128. CheckMenuItem(hMenu, d, MF_CHECKED);
  129. prevCheck = d;
  130. }
  131. /*--------------------------------------------------------------------------*/
  132. /* */
  133. /* clearboard() - */
  134. /* */
  135. /*--------------------------------------------------------------------------*/
  136. VOID NEAR PASCAL clearboard(
  137. BYTE b[max_depth+2][BoardSize])
  138. {
  139. register INT i,j;
  140. INT k;
  141. for (i=0; i<=max_depth ; i++)
  142. for (j=0 ; j<=99 ; j++)
  143. b[i][j] = edge;
  144. for (i=0 ; i<=max_depth ; i++)
  145. {
  146. for (j=11 ; j<=81 ; j=j+10)
  147. for (k=j ; k<j+8 ; k++)
  148. b[i][k] = empty;
  149. b[i][45]=computer;
  150. b[i][54]=computer;
  151. b[i][44]=human;
  152. b[i][55]=human;
  153. }
  154. }
  155. /*--------------------------------------------------------------------------*/
  156. /* */
  157. /* RevCreate() - */
  158. /* */
  159. /*--------------------------------------------------------------------------*/
  160. /* Called on WM_CREATE messages. */
  161. VOID NEAR PASCAL RevCreate(
  162. register HWND hWindow)
  163. {
  164. register HDC hDC;
  165. TEXTMETRIC charsize; /* characteristics of the characters */
  166. MessageOn = FALSE;
  167. hDC = GetDC(hWindow);
  168. GetTextMetrics(hDC, (LPTEXTMETRIC)&charsize);
  169. charheight = charsize.tmHeight;
  170. charwidth = charsize.tmAveCharWidth;
  171. ReleaseDC(hWindow, hDC);
  172. if (COLOR == TRUE)
  173. {
  174. brComputer = brBlue;
  175. brHuman = brRed;
  176. }
  177. else
  178. {
  179. brComputer = brBlack;
  180. brHuman = brWhite;
  181. }
  182. TXMIN = 45 * ASPECT;
  183. clearboard(board);
  184. /* Okay to pass on first move */
  185. fPass = PASS;
  186. depth = 1;
  187. prevCheck = EASY;
  188. ffirstmove = TRUE;
  189. checkdepth(hWindow, prevCheck);
  190. }
  191. /*--------------------------------------------------------------------------*/
  192. /* */
  193. /* printboard() - */
  194. /* */
  195. /*--------------------------------------------------------------------------*/
  196. VOID NEAR PASCAL printboard(
  197. BYTE b[max_depth+2][BoardSize])
  198. {
  199. register INT i,j;
  200. INT sq;
  201. for (i=0; i < 8; i++)
  202. {
  203. for (j=0; j < 8; j++)
  204. {
  205. if ((sq = (INT)b[0][i*10+j+11]) != empty)
  206. {
  207. Brush *brush;
  208. if (sq == computer)
  209. brush = brComputer;
  210. else
  211. brush = brHuman;
  212. g->FillEllipse(brush,
  213. Bx+2*ASPECT+i*xExt,
  214. By+2+j*yExt,
  215. xExt-4*ASPECT,
  216. yExt-4);
  217. }
  218. }
  219. }
  220. }
  221. /*--------------------------------------------------------------------------*/
  222. /* */
  223. /* ClearMessageTop() - */
  224. /* */
  225. /*--------------------------------------------------------------------------*/
  226. VOID NEAR PASCAL ClearMessageTop(
  227. Graphics *graphics)
  228. {
  229. if (MessageOn == TRUE)
  230. {
  231. flashtimes = count + 1;
  232. graphics->FillRectangle((COLOR) ? brGreen : brWhite, 0, 0, xscr, charheight);
  233. MessageOn = FALSE;
  234. }
  235. }
  236. /*--------------------------------------------------------------------------*/
  237. /* */
  238. /* ShowMessageTop() - */
  239. /* */
  240. /*--------------------------------------------------------------------------*/
  241. VOID NEAR PASCAL ShowMessageTop(
  242. Graphics *graphics,
  243. PWSTR string
  244. )
  245. {
  246. INT dx;
  247. pDisplayMessage = string;
  248. ClearMessageTop(graphics);
  249. RectF rect(0, 0, xscr, charheight);
  250. graphics->FillRectangle(brWhite, rect);
  251. Font font((HFONT)NULL);
  252. graphics->DrawStringI((LPWSTR)string,
  253. NULL,
  254. 0,
  255. 0,
  256. NULL, 0,
  257. brBlue);
  258. MessageOn = TRUE;
  259. }
  260. /*--------------------------------------------------------------------------*/
  261. /* */
  262. /* drawboard() - */
  263. /* */
  264. /*--------------------------------------------------------------------------*/
  265. VOID NEAR PASCAL drawboard(
  266. BYTE b[max_depth+2][BoardSize])
  267. {
  268. register INT i;
  269. INT lcx,lcy;
  270. register INT xdimension;
  271. INT xLineExt,yLineExt;
  272. yLineExt = 8 * yExt;
  273. xLineExt = 8 * xExt;
  274. xdimension = dimension * ASPECT;
  275. g->FillRectangle(brBlack, Bx+2*xdimension, By+2*dimension, xLineExt, yLineExt);
  276. g->FillRectangle(brPat, Bx, By, xLineExt, yLineExt);
  277. for (i=Bx; i <= Bx + xLineExt; i += xExt)
  278. g->FillRectangle(brGreen, i, By, ASPECT, yLineExt);
  279. for (i=By; i <= By + yLineExt; i += yExt)
  280. g->FillRectangle(brGreen, Bx, i, xLineExt, 1);
  281. lcx = Bx+xLineExt;
  282. lcy = By+yLineExt;
  283. for (i=1; i < xdimension; ++i)
  284. g->FillRectangle(brPat, lcx+i, By+i/ASPECT, 1, yLineExt);
  285. /* Fill in bottom edge of puzzle. */
  286. for (i=1; i < dimension; ++i)
  287. g->FillRectangle(brPat, Bx+i*ASPECT, lcy+i, xLineExt, 1);
  288. Pen pen(brBlack, 1.0f, UnitWorld);
  289. g->DrawLine(&pen, lcx, By, lcx+xdimension, By+dimension);
  290. g->DrawLine(&pen, lcx+xdimension, By+dimension, lcx+xdimension, lcy+dimension);
  291. g->DrawLine(&pen, lcx+xdimension, lcy+dimension, Bx+xdimension, lcy+dimension);
  292. g->DrawLine(&pen, Bx+xdimension, lcy+dimension, Bx, lcy);
  293. g->DrawLine(&pen, lcx+xdimension, lcy+dimension, lcx, lcy);
  294. printboard(b);
  295. }
  296. /*--------------------------------------------------------------------------*/
  297. /* */
  298. /* RevPaint() - */
  299. /* */
  300. /*--------------------------------------------------------------------------*/
  301. /* Called on WM_PAINT messages. */
  302. VOID NEAR PASCAL RevPaint(
  303. HWND hWindow,
  304. Graphics *graphics)
  305. {
  306. register INT Tx, Ty;
  307. INT xLineExt, yLineExt;
  308. RECT lpSize;
  309. /* Since it is easy to resize we'll do it on every repaint */
  310. g = graphics;
  311. hWin = hWindow;
  312. //SetBkMode(hDisp, OPAQUE);
  313. GetClientRect(hWindow, (LPRECT)&lpSize);
  314. xscr = Tx = lpSize.right - lpSize.left;
  315. Ty = lpSize.bottom - lpSize.top;
  316. /* Dont go below minimum size */
  317. if (Tx < Ty*ASPECT)
  318. {
  319. if (Tx < TXMIN)
  320. Tx = TXMIN;
  321. xExt = Tx / (9 + 1);
  322. yExt = xExt / ASPECT;
  323. }
  324. else
  325. {
  326. if (Ty < TYMIN)
  327. Ty = TYMIN;
  328. yExt = Ty / (9 + 1);
  329. xExt = yExt * ASPECT;
  330. }
  331. yLineExt = 8 * yExt;
  332. xLineExt = 8 * xExt;
  333. dimension = yLineExt/30;
  334. Bx = (Tx > xLineExt) ? (Tx - xLineExt) / 2 : 0;
  335. By = (Ty > yLineExt) ? (Ty - yLineExt) / 2 : 0;
  336. RECT rect;
  337. GetClientRect(hWindow, &rect);
  338. g->FillRectangle(brWhite,
  339. rect.left,
  340. rect.top,
  341. rect.right-rect.left,
  342. rect.bottom-rect.top);
  343. drawboard(board);
  344. if (MessageOn)
  345. {
  346. ShowMessageTop(graphics, pDisplayMessage);
  347. //PatBlt(hDC, 0, 0, xscr, charheight, DSTINVERT);
  348. }
  349. }
  350. /*--------------------------------------------------------------------------*/
  351. /* */
  352. /* FlashMessageTop() - */
  353. /* */
  354. /*--------------------------------------------------------------------------*/
  355. VOID NEAR PASCAL FlashMessageTop(
  356. HWND hWindow)
  357. {
  358. flashtimes = 0;
  359. count = 4;
  360. SetTimer(hWindow, 666, 200, InverseMessage); /* Timer ID is 666 */
  361. }
  362. /*--------------------------------------------------------------------------*/
  363. /* */
  364. /* RevMessage() - */
  365. /* */
  366. /*--------------------------------------------------------------------------*/
  367. VOID NEAR PASCAL RevMessage(
  368. HWND hWindow,
  369. Graphics *graphics,
  370. register WCHAR *pS,
  371. INT n,
  372. WCHAR *pchPostStr)
  373. {
  374. register WCHAR *pch;
  375. pch = strBuf;
  376. while (*pS)
  377. *pch++ = *pS++;
  378. if (n)
  379. {
  380. if (n / 10)
  381. *pch++ = (CHAR)(n / 10 + L'0');
  382. *pch++ = (CHAR)(n % 10 + L'0');
  383. }
  384. if (pchPostStr)
  385. {
  386. while (*pchPostStr)
  387. *pch++ = *pchPostStr++;
  388. }
  389. *pch = L'\0';
  390. ShowMessageTop(graphics, strBuf);
  391. FlashMessageTop(hWindow);
  392. }
  393. /*--------------------------------------------------------------------------*/
  394. /* */
  395. /* flashsqr() - */
  396. /* */
  397. /*--------------------------------------------------------------------------*/
  398. VOID NEAR PASCAL flashsqr(
  399. register Graphics *graphics,
  400. INT x1,
  401. INT y1,
  402. INT Ex,
  403. INT Ey,
  404. INT color,
  405. BOOL fBlankSquare,
  406. INT n)
  407. {
  408. register INT i;
  409. // !! ??
  410. // if (fBlankSquare)
  411. // SelectObject(hDC, GetStockObject(NULL_PEN));
  412. SetCursor((HICON)curBlank);
  413. for (i=0; i < n; ++i)
  414. {
  415. if (color == 1)
  416. color = 2;
  417. else
  418. color = 1;
  419. Brush *brush;
  420. if (color == 1)
  421. brush = brComputer;
  422. else
  423. brush = brHuman;
  424. graphics->FillEllipse(brush, x1, y1, Ex, Ey);
  425. }
  426. if (fBlankSquare)
  427. {
  428. graphics->FillEllipse(brPat, x1, y1, Ex, Ey);
  429. }
  430. else
  431. SetCursor((HICON)curThink);
  432. }
  433. /*--------------------------------------------------------------------------*/
  434. /* */
  435. /* RevMouseMove() - */
  436. /* */
  437. /*--------------------------------------------------------------------------*/
  438. VOID NEAR PASCAL RevMouseMove(
  439. POINT point)
  440. {
  441. INT move;
  442. INT Si, Sj;
  443. INT yLineExt = 8 * yExt;
  444. INT xLineExt = 8 * xExt;
  445. HANDLE cur;
  446. MousePos.x = point.x;
  447. MousePos.y = point.y;
  448. if(xExt ==0 || yExt == 0)
  449. return;
  450. cur = curIllegal;
  451. if ((point.x > Bx) && (point.x < (Bx+xLineExt)) && (point.y > By) && (point.y < (By+yLineExt)))
  452. {
  453. Si = (point.x - Bx) / xExt;
  454. Sj = (point.y - By) / yExt;
  455. move = Si * 10 + Sj + 11;
  456. if (legalcheck(board[0], move, human, computer))
  457. cur = curLegal;
  458. }
  459. SetCursor((HICON)cur);
  460. }
  461. /*--------------------------------------------------------------------------*/
  462. /* */
  463. /* ShowBestMove() - */
  464. /* */
  465. /*--------------------------------------------------------------------------*/
  466. VOID NEAR PASCAL ShowBestMove(
  467. HWND hwnd)
  468. {
  469. HDC hdc;
  470. INT sq;
  471. register INT x, y;
  472. INT *pMoves;
  473. BOOL bDone;
  474. if (fPass == PASS && !ffirstmove)
  475. return;
  476. if (!fCheated)
  477. SetWindowText(hwnd, (LPWSTR)szReversiPractice);
  478. fCheated = TRUE;
  479. SetCursor((HICON)curThink);
  480. fThinking = TRUE;
  481. if (ffirstmove)
  482. {
  483. /* HACK: Hardcode the first move hint. */
  484. x = 4;
  485. y = 2;
  486. }
  487. else
  488. {
  489. if (depth == 1)
  490. {
  491. bDone = FALSE;
  492. pMoves = moves;
  493. sq = *pMoves;
  494. while (!bDone)
  495. {
  496. sq = *pMoves;
  497. if (legalcheck(board[0], sq, human, computer))
  498. bDone = TRUE;
  499. else
  500. pMoves++;
  501. }
  502. y = (sq - 11) % 10;
  503. x = (sq - 11) / 10;
  504. }
  505. else
  506. {
  507. minmax(board, BestMove[0], computer, human, 1, -infin, infin);
  508. y = (BestMove[1] - 11) % 10;
  509. x = (BestMove[1] - 11) / 10;
  510. }
  511. }
  512. MousePos.x = (x * xExt) + Bx + xExt/2;
  513. MousePos.y = (y * yExt) + By + yExt/2;
  514. UpdateCursor(hwnd);
  515. Graphics graphics(hwnd);
  516. x = x * xExt + Bx + 2 * ASPECT;
  517. y = y * yExt + By + 2;
  518. flashsqr(&graphics, x, y, xExt - 4 * ASPECT, yExt - 4, computer, TRUE, 3);
  519. fThinking = FALSE;
  520. RevMouseMove(MousePos);
  521. }
  522. /*--------------------------------------------------------------------------*/
  523. /* */
  524. /* gameover() - */
  525. /* */
  526. /*--------------------------------------------------------------------------*/
  527. /* Find a human reply to the computers move.
  528. * As a side effect set flag fPass if the human
  529. * has a legal move.
  530. */
  531. VOID NEAR PASCAL gameover(
  532. register HWND hWindow,
  533. Graphics *g,
  534. BYTE b[max_depth + 2][BoardSize],
  535. INT r)
  536. {
  537. register INT i;
  538. INT cc;
  539. INT hc;
  540. INT sq;
  541. INT reply2;
  542. INT *pMoves;
  543. pMoves = moves;
  544. fPass = PASS;
  545. reply2 = PASS;
  546. while ((sq = *pMoves++) != 0)
  547. {
  548. if (legalcheck(b[0], sq, human, computer))
  549. fPass = sq;
  550. else if (legalcheck(b[0], sq, computer, human))
  551. reply2 = sq;
  552. }
  553. if (fPass == PASS)
  554. {
  555. if ((r == PASS) || (reply2 == PASS))
  556. {
  557. hc = 0;
  558. cc = 0;
  559. for (i=11; i <= 88; i++)
  560. {
  561. if (b[0][i] == human)
  562. hc++;
  563. else if (b[0][i] == computer)
  564. cc++;
  565. }
  566. if (hc > cc)
  567. RevMessage(hWindow, g, szWon, hc-cc, szWonPost);
  568. else if (hc < cc)
  569. RevMessage(hWindow, g, szLoss, cc-hc, szLossPost);
  570. else
  571. RevMessage(hWindow, g, szTie, 0, NULL);
  572. }
  573. else
  574. {
  575. RevMessage(hWindow, g, szMustPass, 0, NULL);
  576. }
  577. }
  578. else if (r == PASS)
  579. {
  580. RevMessage(hWindow, g, szPass, 0, NULL);
  581. }
  582. }
  583. /*--------------------------------------------------------------------------*/
  584. /* */
  585. /* paintmove() - */
  586. /* */
  587. /*--------------------------------------------------------------------------*/
  588. /* Make a move and show the results. */
  589. VOID NEAR PASCAL paintmove(
  590. BYTE b[BoardSize],
  591. INT move,
  592. INT friendly,
  593. INT enemy)
  594. {
  595. INT d;
  596. INT sq;
  597. INT *p;
  598. register INT i,j;
  599. INT color;
  600. if (move != PASS)
  601. {
  602. Brush *brush;
  603. if (friendly == computer)
  604. {
  605. brush = brComputer;
  606. color = 1;
  607. }
  608. else
  609. {
  610. brush = brHuman;
  611. color = 2;
  612. }
  613. i = ((move - 11) / 10) * xExt + Bx + 2 * ASPECT;
  614. j = ((move - 11) % 10) * yExt + By + 2;
  615. Pen pen(brush, 1.0f, UnitWorld);
  616. g->DrawEllipse(&pen, i, j, xExt - 4 * ASPECT, yExt - 4);
  617. flashsqr(g, i, j, xExt - 4 * ASPECT, yExt - 4, color, FALSE, 4);
  618. p = direc;
  619. while ((d = *p++) != 0)
  620. {
  621. sq=move;
  622. if (b[sq += d] == enemy)
  623. {
  624. while(b[sq += d] == enemy)
  625. ;
  626. if (b[sq] == (BYTE)friendly)
  627. {
  628. while(b[sq -= d] == enemy)
  629. {
  630. board[0][sq] = b[sq] = friendly;
  631. i = ((sq - 11)/10)*xExt+Bx+2*ASPECT;
  632. j = ((sq - 11)%10)*yExt+By+2;
  633. g->FillEllipse(brush, i, j, xExt-4*ASPECT, yExt-4);
  634. }
  635. }
  636. }
  637. }
  638. b[move]=friendly;
  639. }
  640. }
  641. /*--------------------------------------------------------------------------*/
  642. /* */
  643. /* RevMenu() - */
  644. /* */
  645. /*--------------------------------------------------------------------------*/
  646. /* Called on WM_COMMAND messages. */
  647. VOID NEAR PASCAL RevMenu(
  648. register HWND hWindow,
  649. INT idval)
  650. {
  651. HDC hDC;
  652. register INT cmd;
  653. if (fThinking)
  654. return;
  655. hWin = hWindow;
  656. switch (idval)
  657. {
  658. case EXIT:
  659. PostMessage(hWindow, WM_CLOSE, 0, 0L);
  660. break;
  661. case MN_HELP_ABOUT:
  662. DialogBox((HINSTANCE)hInst, MAKEINTRESOURCE(3), hWindow, AboutDlgProc);
  663. break;
  664. case MN_HELP_INDEX:
  665. //TEMPFIX WinHelp(hWindow, (LPSTR)szHelpFile, HELP_INDEX, 0L);
  666. break;
  667. case MN_HELP_USINGHELP:
  668. //TEMPFIX WinHelp(hWindow, (LPSTR)NULL, HELP_HELPONHELP, 0L);
  669. break;
  670. case MN_HELP_KEYBOARD:
  671. cmd = 0x1e;
  672. goto HelpCommon;
  673. case MN_HELP_COMMANDS:
  674. cmd = 0x20;
  675. goto HelpCommon;
  676. case MN_HELP_PLAYING:
  677. cmd = 0x21;
  678. goto HelpCommon;
  679. case MN_HELP_RULES:
  680. cmd = 0x22;
  681. HelpCommon:
  682. //TEMPFIX WinHelp(hWindow, (LPSTR)szHelpFile, HELP_CONTEXT, (DWORD)cmd);
  683. break;
  684. case HINT:
  685. ShowBestMove(hWindow);
  686. return;
  687. break;
  688. case NEW:
  689. SetWindowText(hWindow , (LPWSTR)szReversi);
  690. ffirstmove = TRUE;
  691. g = new Graphics(hWindow);
  692. fCheated = FALSE;
  693. ClearMessageTop(g);
  694. fPass = PASS;
  695. clearboard(board);
  696. drawboard(board);
  697. delete g;
  698. g = NULL;
  699. break;
  700. case EASY:
  701. depth = 1; /* MUST BE AT LEAST 1. */
  702. checkdepth(hWindow, EASY); /* KEEP HANDS OFF! */
  703. break;
  704. case MEDIUM:
  705. depth = 2;
  706. checkdepth(hWindow, MEDIUM);
  707. break;
  708. case HARD:
  709. depth = 4;
  710. checkdepth(hWindow, HARD);
  711. break;
  712. case VHARD:
  713. depth = 6;
  714. checkdepth(hWindow, VHARD);
  715. break;
  716. case PASS:
  717. if (fPass == PASS)
  718. {
  719. g = new Graphics(hWindow);
  720. fThinking = TRUE;
  721. ClearMessageTop(g);
  722. SetCursor((HICON)curThink);
  723. delete g;
  724. g = NULL;
  725. minmax(board, PASS, human, computer, 0, -infin, infin);
  726. g = new Graphics(hWindow);
  727. paintmove(board[0], BestMove[0], (BYTE)computer, (BYTE)human);
  728. gameover(hWindow, g, board, BestMove[0]);
  729. SetCursor((HICON)curIllegal);
  730. fThinking = FALSE;
  731. delete g;
  732. g = NULL;
  733. }
  734. else
  735. MessageBox(hWindow, (LPWSTR)szNoPass, (LPWSTR)szReversi, MB_OK | MB_ICONASTERISK);
  736. break;
  737. }
  738. }
  739. /*--------------------------------------------------------------------------*/
  740. /* */
  741. /* msgcheck() - */
  742. /* */
  743. /*--------------------------------------------------------------------------*/
  744. /* Called by ASM routine to allow other tasks to run. */
  745. BOOL NEAR PASCAL msgcheck()
  746. {
  747. MSG msg;
  748. if (PeekMessage((LPMSG)&msg, NULL, 0, 0, TRUE))
  749. {
  750. if (msg.message == WM_QUIT)
  751. exit(0);
  752. if (TranslateAccelerator(msg.hwnd, (HACCEL)hAccel, (LPMSG)&msg) == 0)
  753. {
  754. TranslateMessage((LPMSG)&msg);
  755. DispatchMessage((LPMSG)&msg);
  756. }
  757. return(TRUE);
  758. }
  759. return(FALSE);
  760. }
  761. /*--------------------------------------------------------------------------*/
  762. /* */
  763. /* RevInit() - */
  764. /* */
  765. /*--------------------------------------------------------------------------*/
  766. BOOL NEAR PASCAL RevInit(
  767. HANDLE hInstance)
  768. {
  769. register PWNDCLASS pRevClass;
  770. HDC hdc;
  771. static INT rgpat[] = { 170, 85, 170, 85, 170, 85, 170, 85 };
  772. brWhite = new SolidBrush(Color::White);
  773. brBlack = new SolidBrush(Color::Black);
  774. Bitmap *bmdel = new Bitmap(8, 8, 4, PIXFMT_1BPP_INDEXED, (BYTE*)rgpat);
  775. brPat = new TextureBrush((Bitmap *)bmdel);
  776. if (!brPat)
  777. return(FALSE);
  778. delete bmdel;
  779. ffirstmove = TRUE;
  780. hdc = GetDC((HWND)NULL);
  781. COLOR = GetDeviceCaps(hdc, NUMCOLORS) > 2;
  782. if (GetDeviceCaps(hdc, VERTRES) == 200)
  783. ASPECT = 2;
  784. else
  785. ASPECT = 1;
  786. ReleaseDC((HWND)NULL, hdc);
  787. brRed = new SolidBrush(Color::Red);
  788. brGreen = new SolidBrush(Color::Green);
  789. brBlue = new SolidBrush(Color::Blue);
  790. LOGBRUSH logbrush;
  791. logbrush.lbStyle = BS_SOLID;
  792. logbrush.lbColor = Color::White;
  793. logbrush.lbHatch = 0;
  794. hbrWhite = CreateBrushIndirect(&logbrush);
  795. logbrush.lbColor = Color::Green;
  796. hbrGreen = CreateBrushIndirect(&logbrush);
  797. if (!brRed || !brGreen || !brBlue || !hbrWhite || !hbrGreen)
  798. return(FALSE);
  799. LoadStringW((HINSTANCE)hInstance, 3, (LPWSTR)szReversi, 20);
  800. LoadStringW((HINSTANCE)hInstance, 4, (LPWSTR)szReversiPractice, 40);
  801. LoadStringW((HINSTANCE)hInstance, 5, (LPWSTR)szPass, 30);
  802. LoadStringW((HINSTANCE)hInstance, 6, (LPWSTR)szMustPass, 30);
  803. LoadStringW((HINSTANCE)hInstance, 7, (LPWSTR)szTie, 30);
  804. LoadStringW((HINSTANCE)hInstance, 8, (LPWSTR)szLoss, 30);
  805. LoadStringW((HINSTANCE)hInstance, 9, (LPWSTR)szWon, 30);
  806. LoadStringW((HINSTANCE)hInstance, 10, (LPWSTR)szAbout, 20);
  807. LoadStringW((HINSTANCE)hInstance, 11, (LPWSTR)szLossPost, 30);
  808. LoadStringW((HINSTANCE)hInstance, 12, (LPWSTR)szWonPost, 30);
  809. LoadStringW((HINSTANCE)hInstance, 13, (LPWSTR)szIllegal, 70);
  810. LoadStringW((HINSTANCE)hInstance, 14, (LPWSTR)szNoPass, 70);
  811. LoadStringW((HINSTANCE)hInstance, 15, (LPWSTR)szHelpFile, 15);
  812. hAccel = LoadAccelerators((HINSTANCE)hInstance, (LPWSTR)"MAINACC");
  813. pRevClass = (PWNDCLASS)((CHAR *)LocalAlloc(LMEM_ZEROINIT, sizeof(WNDCLASS)));
  814. if (!pRevClass)
  815. return(FALSE);
  816. curLegal = LoadCursorW(NULL, IDC_CROSS);
  817. curIllegal = LoadCursorW(NULL, IDC_ARROW);
  818. curThink = LoadCursorW(NULL, IDC_WAIT);
  819. curBlank = LoadCursorW((HINSTANCE)hInstance, MAKEINTRESOURCE(1));
  820. if (!curLegal || !curIllegal || !curThink || !curBlank)
  821. return(FALSE);
  822. pRevClass->hIcon = LoadIcon((HINSTANCE)hInstance, MAKEINTRESOURCE(3));
  823. pRevClass->lpszClassName = (LPWSTR)"Reversi";
  824. pRevClass->hbrBackground = ((COLOR) ? hbrGreen : hbrWhite);
  825. pRevClass->lpfnWndProc = ReversiWndProc;
  826. pRevClass->lpszMenuName = MAKEINTRESOURCE(1);
  827. pRevClass->hInstance = (HINSTANCE)hInstance;
  828. pRevClass->style = CS_VREDRAW | CS_HREDRAW | CS_BYTEALIGNCLIENT;
  829. if (!RegisterClass((LPWNDCLASS)pRevClass))
  830. {
  831. LocalFree((HANDLE)pRevClass);
  832. return(FALSE);
  833. }
  834. LocalFree((HANDLE)pRevClass);
  835. return(TRUE);
  836. }
  837. /*--------------------------------------------------------------------------*/
  838. /* */
  839. /* RevMouseClick() - */
  840. /* */
  841. /*--------------------------------------------------------------------------*/
  842. VOID NEAR PASCAL RevMouseClick(
  843. HWND hWnd,
  844. POINT point)
  845. {
  846. INT move;
  847. INT Si, Sj;
  848. INT yLineExt = 8 * yExt;
  849. INT xLineExt = 8 * xExt;
  850. HDC hDC;
  851. MousePos.x = point.x;
  852. MousePos.y = point.y;
  853. if (xExt == 0 || yExt == 0)
  854. return;
  855. if ((point.x > Bx) && (point.x < (Bx+xLineExt)) && (point.y > By) && (point.y < (By+yLineExt)))
  856. {
  857. Si = (point.x - Bx) / xExt;
  858. Sj = (point.y - By) / yExt;
  859. move = Si * 10 + Sj + 11;
  860. if (legalcheck(board[0], move, human, computer))
  861. {
  862. board[0][move] = human;
  863. ffirstmove = FALSE;
  864. fThinking = TRUE;
  865. SetCursor((HICON)curThink);
  866. Graphics *gtemp;
  867. gtemp = g = new Graphics(hWnd);
  868. ClearMessageTop(g);
  869. minmax(board, move, human, computer, 0, -infin, infin);
  870. makemove(board[0], move, human, computer);
  871. g = gtemp;
  872. paintmove(board[0], BestMove[0], computer, human);
  873. gameover(hWnd, g, board, BestMove[0]);
  874. delete g;
  875. g = NULL;
  876. SetCursor((HICON)curIllegal);
  877. fThinking = FALSE;
  878. }
  879. else
  880. MessageBox(hWnd, (LPWSTR)szIllegal, (LPWSTR)szReversi, MB_OK | MB_ICONASTERISK);
  881. }
  882. }
  883. /*--------------------------------------------------------------------------*/
  884. /* */
  885. /* Next() - */
  886. /* */
  887. /*--------------------------------------------------------------------------*/
  888. VOID NEAR PASCAL Next(
  889. register INT *px,
  890. register INT *py)
  891. {
  892. (*px)++;
  893. if (*px > 7)
  894. {
  895. *px = 0;
  896. (*py)++;
  897. if (*py > 7)
  898. *py = 0;
  899. }
  900. }
  901. /*--------------------------------------------------------------------------*/
  902. /* */
  903. /* Previous() - */
  904. /* */
  905. /*--------------------------------------------------------------------------*/
  906. VOID NEAR PASCAL Previous(
  907. register INT *px,
  908. register INT *py)
  909. {
  910. (*px)--;
  911. if (*px < 0)
  912. {
  913. *px = 7;
  914. (*py)--;
  915. if (*py < 0)
  916. *py = 7;
  917. }
  918. }
  919. /*--------------------------------------------------------------------------*/
  920. /* */
  921. /* ShowNextMove() - */
  922. /* */
  923. /*--------------------------------------------------------------------------*/
  924. VOID NEAR PASCAL ShowNextMove(
  925. HWND hwnd,
  926. BOOL fforward)
  927. {
  928. INT x, y;
  929. INT potentialmove;
  930. BOOL done;
  931. /* What out for infinite loops. */
  932. if (fPass == PASS && !ffirstmove)
  933. return;
  934. x = (MousePos.x - Bx) / xExt;
  935. y = (MousePos.y - By) / yExt;
  936. done = FALSE;
  937. while (!done)
  938. {
  939. do
  940. {
  941. if (fforward)
  942. Next(&x, &y);
  943. else
  944. Previous(&x, &y);
  945. }
  946. while ((board[0][potentialmove = (x * 10 + y + 11)]) != empty);
  947. fThinking = TRUE;
  948. if (legalcheck(board[0], potentialmove, human, computer))
  949. done = TRUE;
  950. fThinking = FALSE;
  951. }
  952. MousePos.x = x * xExt + Bx + xExt / 2;
  953. MousePos.y = y * yExt + By + yExt / 2;
  954. UpdateCursor(hwnd);
  955. RevMouseMove(MousePos);
  956. }
  957. /*--------------------------------------------------------------------------*/
  958. /* */
  959. /* RevChar() - */
  960. /* */
  961. /*--------------------------------------------------------------------------*/
  962. VOID NEAR PASCAL RevChar(
  963. HWND hwnd,
  964. register WORD code)
  965. {
  966. INT a;
  967. POINT curpoint;
  968. curpoint.x = curpoint.y = 1;
  969. switch (code)
  970. {
  971. case 0x27:
  972. MousePos.x += xExt;
  973. break;
  974. case 0x28:
  975. MousePos.y += yExt;
  976. break;
  977. case 0x25:
  978. curpoint.x = (MousePos.x - Bx)/xExt;
  979. MousePos.x -= xExt;
  980. break;
  981. case 0x26:
  982. curpoint.y = (MousePos.y - By)/yExt;
  983. MousePos.y -= yExt;
  984. break;
  985. case 0x24:
  986. curpoint.y = (MousePos.y - By)/yExt;
  987. curpoint.x = (MousePos.x - Bx)/xExt;
  988. MousePos.y -= yExt;
  989. MousePos.x -= xExt;
  990. break;
  991. case 0x21:
  992. curpoint.y = (MousePos.y - By)/yExt;
  993. MousePos.y -= yExt;
  994. MousePos.x += xExt;
  995. break;
  996. case 0x23:
  997. curpoint.x = (MousePos.x - Bx)/xExt;
  998. MousePos.y += yExt;
  999. MousePos.x -= xExt;
  1000. break;
  1001. case 0x22:
  1002. MousePos.y += yExt;
  1003. MousePos.x += xExt;
  1004. break;
  1005. case 0x0020:
  1006. case 0x000D:
  1007. if (!fThinking)
  1008. RevMouseClick(hwnd, MousePos);
  1009. return;
  1010. case 0x0009:
  1011. if (fThinking)
  1012. break;
  1013. if (GetKeyState(VK_SHIFT) < 0)
  1014. ShowNextMove(hwnd, FALSE); /* look backwards */
  1015. else
  1016. ShowNextMove(hwnd, TRUE); /* look forwards */
  1017. return;
  1018. default:
  1019. return;
  1020. }
  1021. if (((a = ((MousePos.x - Bx) / xExt)) >7) || a <= 0)
  1022. MousePos.x = Bx + xExt / 2; /* wrap around horizontally */
  1023. if (a > 8 || (curpoint.x == 0 && a == 0))
  1024. MousePos.x = (7*xExt) + Bx + xExt / 2 ;
  1025. if ( ((a = ((MousePos.y - By) / yExt)) >7) || a <= 0)
  1026. MousePos.y = By + yExt / 2;
  1027. if ( a > 8 || (curpoint.y == 0 && a == 0))
  1028. MousePos.y = (7*yExt) + By + yExt / 2;
  1029. MousePos.x = ((MousePos.x - Bx) / xExt) * xExt + Bx + xExt / 2;
  1030. MousePos.y = ((MousePos.y - By) / yExt) * yExt + By + yExt / 2;
  1031. UpdateCursor(hwnd);
  1032. RevMouseMove(MousePos);
  1033. }
  1034. /*--------------------------------------------------------------------------*/
  1035. /* */
  1036. /* InverseMessage() - */
  1037. /* */
  1038. /*--------------------------------------------------------------------------*/
  1039. VOID APIENTRY InverseMessage(
  1040. register HWND hWindow,
  1041. UINT message,
  1042. UINT_PTR wParam,
  1043. DWORD lParam)
  1044. {
  1045. HDC hDC;
  1046. message;
  1047. wParam;
  1048. lParam;
  1049. if (flashtimes <= count)
  1050. {
  1051. // !! THIS STILL NEEDS WORK: How to do Inversion?
  1052. //Graphics graphics(hWindow);
  1053. // graphics.FillRectangle(hDC, 0, 0, xscr, charheight, DSTINVERT);
  1054. // flashtimes++;
  1055. // ReleaseDC(hWindow, hDC);
  1056. }
  1057. else
  1058. KillTimer(hWindow, 666);
  1059. return;
  1060. }
  1061. /*--------------------------------------------------------------------------*/
  1062. /* */
  1063. /* ReversiWndProc() - */
  1064. /* */
  1065. /*--------------------------------------------------------------------------*/
  1066. LRESULT APIENTRY ReversiWndProc(
  1067. HWND hWnd,
  1068. register UINT message,
  1069. WPARAM wParam,
  1070. LPARAM lParam)
  1071. {
  1072. HMENU hm;
  1073. PAINTSTRUCT ps;
  1074. POINT curpoint;
  1075. switch (message)
  1076. {
  1077. case WM_COMMAND:
  1078. RevMenu(hWnd, GET_WM_COMMAND_ID(wParam, lParam));
  1079. break;
  1080. case WM_INITMENU: /* disable the menu if thinking */
  1081. hm = GetMenu(hWnd);
  1082. if (fThinking)
  1083. {
  1084. EnableMenuItem(hm, 0, MF_DISABLED | MF_BYPOSITION);
  1085. EnableMenuItem(hm, 1, MF_DISABLED | MF_BYPOSITION);
  1086. }
  1087. else
  1088. {
  1089. EnableMenuItem(hm, 0, MF_ENABLED | MF_BYPOSITION);
  1090. EnableMenuItem(hm, 1, MF_ENABLED | MF_BYPOSITION);
  1091. }
  1092. break;
  1093. case WM_CREATE:
  1094. RevCreate(hWnd);
  1095. hWin = hWnd;
  1096. break;
  1097. case WM_CLOSE:
  1098. if (hDisp)
  1099. ReleaseDC(hWnd, hDisp);
  1100. return(DefWindowProc(hWnd, message, wParam, lParam));
  1101. case WM_DESTROY:
  1102. if (MGetModuleUsage(hInst) == 1)
  1103. {
  1104. delete brGreen;
  1105. delete brPat;
  1106. delete brRed;
  1107. delete brBlue;
  1108. }
  1109. /* In case WinHelp keys off hWindow, we need to do the HELP_QUIT
  1110. * here instead of when there is just one instance of help...
  1111. */
  1112. //TEMPFIX WinHelp(hWnd, (LPSTR)szHelpFile, HELP_QUIT, 0L);
  1113. PostQuitMessage(0);
  1114. break;
  1115. case WM_KEYDOWN:
  1116. if (IsIconic(hWnd))
  1117. return 0L;
  1118. RevChar(hWnd, (WORD)wParam);
  1119. break;
  1120. case WM_ACTIVATE:
  1121. if (!GetSystemMetrics(SM_MOUSEPRESENT))
  1122. {
  1123. if (GET_WM_ACTIVATE_STATE(wParam, lParam))
  1124. {
  1125. if (GET_WM_ACTIVATE_HWND(wParam, lParam) != hWnd)
  1126. {
  1127. curpoint.x = MousePos.x;
  1128. curpoint.y = MousePos.y;
  1129. ClientToScreen(hWnd, (LPPOINT)&curpoint);
  1130. SetCursorPos(curpoint.x, curpoint.y);
  1131. RevMouseMove(MousePos);
  1132. ShowCursor(GET_WM_ACTIVATE_STATE(wParam, lParam));
  1133. }
  1134. }
  1135. else
  1136. ShowCursor((BOOL) wParam);
  1137. }
  1138. if (wParam && (!HIWORD(lParam)))
  1139. SetFocus(hWnd);
  1140. break;
  1141. case WM_PAINT:
  1142. BeginPaint(hWnd, (LPPAINTSTRUCT)&ps);
  1143. {
  1144. Graphics graphics(ps.hdc);
  1145. RECT rect;
  1146. GetClientRect(hWnd, &rect);
  1147. RectF rectf(rect.left,
  1148. rect.top,
  1149. rect.right-rect.left,
  1150. rect.bottom-rect.top);
  1151. graphics.SetClip(rectf);
  1152. RevPaint(hWnd, &graphics);
  1153. }
  1154. EndPaint(hWnd, (LPPAINTSTRUCT)&ps);
  1155. break;
  1156. case WM_MOUSEMOVE:
  1157. {
  1158. POINT pt;
  1159. LONG2POINT(lParam, pt); /* convert LONG lParam to POINT structure*/
  1160. if (!fThinking)
  1161. #ifdef ORGCODE
  1162. RevMouseMove(MAKEPOINT(lParam));
  1163. #else
  1164. RevMouseMove(pt);
  1165. #endif
  1166. else
  1167. SetCursor((HICON)curThink);
  1168. break;
  1169. }
  1170. case WM_LBUTTONDOWN:
  1171. SetCapture(hWnd);
  1172. bMouseDownInReversi = TRUE;
  1173. break;
  1174. case WM_LBUTTONUP:
  1175. {
  1176. POINT pt;
  1177. LONG2POINT(lParam, pt); /* convert LONG lParam to POINT structure*/
  1178. ReleaseCapture();
  1179. if (!fThinking && bMouseDownInReversi)
  1180. #ifdef ORGCODE
  1181. RevMouseClick(hWnd, MAKEMPOINT(lParam));
  1182. #else
  1183. RevMouseClick(hWnd, pt);
  1184. #endif
  1185. bMouseDownInReversi = FALSE;
  1186. break;
  1187. }
  1188. case WM_TIMER:
  1189. /* This should never be called. */
  1190. break;
  1191. case WM_VSCROLL:
  1192. case WM_HSCROLL:
  1193. break;
  1194. default:
  1195. return(DefWindowProc(hWnd, message, wParam, lParam));
  1196. break;
  1197. }
  1198. return(0L);
  1199. }
  1200. /*--------------------------------------------------------------------------*/
  1201. /* */
  1202. /* AboutDlgProc() */
  1203. /* */
  1204. /*--------------------------------------------------------------------------*/
  1205. INT_PTR APIENTRY AboutDlgProc(
  1206. HWND hDlg,
  1207. UINT message,
  1208. WPARAM wParam,
  1209. LPARAM lParam)
  1210. {
  1211. if (message == WM_COMMAND)
  1212. {
  1213. EndDialog(hDlg, TRUE);
  1214. return(TRUE);
  1215. }
  1216. if (message == WM_INITDIALOG)
  1217. return(TRUE);
  1218. else
  1219. return(FALSE);
  1220. UNREFERENCED_PARAMETER(wParam);
  1221. UNREFERENCED_PARAMETER(lParam);
  1222. }
  1223. /*--------------------------------------------------------------------------*/
  1224. /* */
  1225. /* WinMain() - */
  1226. /* */
  1227. /*--------------------------------------------------------------------------*/
  1228. MMain(hInstance, hPrev, lpszCmdLine, cmdShow) /* { */
  1229. HWND hWnd;
  1230. MSG msg;
  1231. _argc;
  1232. _argv;
  1233. hInst = hInstance;
  1234. if (!hPrev)
  1235. {
  1236. if (!RevInit(hInstance))
  1237. return(FALSE);
  1238. }
  1239. else
  1240. {
  1241. if (fThinking)
  1242. return FALSE;
  1243. #ifdef WIN16
  1244. GetInstanceData(hPrev, (PSTR)&hbrBlack, sizeof(HBRUSH));
  1245. GetInstanceData(hPrev, (PSTR)&hbrPat, sizeof(HBRUSH));
  1246. GetInstanceData(hPrev, (PSTR)&hbrWhite, sizeof(HBRUSH));
  1247. GetInstanceData(hPrev, (PSTR)&hbrRed, sizeof(HBRUSH));
  1248. GetInstanceData(hPrev, (PSTR)&hbrBlue, sizeof(HBRUSH));
  1249. GetInstanceData(hPrev, (PSTR)&hbrGreen, sizeof(HBRUSH));
  1250. GetInstanceData(hPrev, (PSTR)&hbrComputer, sizeof(HBRUSH));
  1251. GetInstanceData(hPrev, (PSTR)&hbrHuman, sizeof(HBRUSH));
  1252. GetInstanceData(hPrev, (PSTR)&curIllegal, sizeof(HCURSOR));
  1253. GetInstanceData(hPrev, (PSTR)&curLegal, sizeof(HCURSOR));
  1254. GetInstanceData(hPrev, (PSTR)&curThink, sizeof(HCURSOR));
  1255. GetInstanceData(hPrev, (PSTR)&curBlank, sizeof(HCURSOR));
  1256. GetInstanceData(hPrev, (PSTR)&prevCheck, sizeof(prevCheck));
  1257. GetInstanceData(hPrev, (PSTR)&depth, sizeof(depth));
  1258. GetInstanceData(hPrev, (PSTR)direc, sizeof(direc));
  1259. GetInstanceData(hPrev, (PSTR)moves, sizeof(moves));
  1260. GetInstanceData(hPrev, (PSTR)szReversi, 20);
  1261. GetInstanceData(hPrev, (PSTR)szReversiPractice, 40);
  1262. GetInstanceData(hPrev, (PSTR)szPass, 10);
  1263. GetInstanceData(hPrev, (PSTR)szMustPass, 20);
  1264. GetInstanceData(hPrev, (PSTR)szTie, 15);
  1265. GetInstanceData(hPrev, (PSTR)szLoss, 15);
  1266. GetInstanceData(hPrev, (PSTR)szWon, 15);
  1267. GetInstanceData(hPrev, (PSTR)szAbout, 20);
  1268. GetInstanceData(hPrev, (PSTR)&COLOR, sizeof(INT));
  1269. GetInstanceData(hPrev, (PSTR)&ASPECT, sizeof(INT));
  1270. GetInstanceData(hPrev, (PSTR)&hAccel, 2);
  1271. GetInstanceData(hPrev, (PSTR)szIllegal, 70);
  1272. GetInstanceData(hPrev, (PSTR)szNoPass, 70);
  1273. GetInstanceData(hPrev, (PSTR)szHelpFile, 15);
  1274. #endif /* WIN16 */
  1275. }
  1276. TYMIN = 45;
  1277. fThinking = FALSE;
  1278. hWnd = CreateWindow((LPWSTR) "Reversi",
  1279. fCheated ? (LPWSTR)szReversiPractice : (LPWSTR)szReversi,
  1280. WS_TILEDWINDOW,
  1281. CW_USEDEFAULT,
  1282. 0,
  1283. (GetSystemMetrics(SM_CXSCREEN) >> 1),
  1284. (GetSystemMetrics(SM_CYSCREEN) * 4 / 5),
  1285. (HWND)NULL,
  1286. (HMENU)NULL,
  1287. (HINSTANCE)hInstance,
  1288. NULL);
  1289. if (!hWnd)
  1290. return(FALSE);
  1291. ShowWindow(hWnd, cmdShow);
  1292. UpdateWindow(hWnd);
  1293. /* Messaging Loop. */
  1294. while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  1295. {
  1296. if (!TranslateAccelerator(msg.hwnd, (HACCEL)hAccel, (LPMSG)&msg))
  1297. {
  1298. TranslateMessage((LPMSG)&msg);
  1299. DispatchMessage((LPMSG)&msg);
  1300. }
  1301. }
  1302. return(0);
  1303. }