home *** CD-ROM | disk | FTP | other *** search
/ MORE WinGames / WINGAMES.iso / winpool / winint.c < prev    next >
C/C++ Source or Header  |  1992-12-31  |  19KB  |  824 lines

  1.  
  2.  
  3. /*
  4.  * I. ARIT 1992 Hidirbeyli,AYDIN,TR.  09400 Golden,    CO,   USA. 80401 
  5.  *
  6.  *
  7.  * Copyright (C) 1992 Ismail ARIT 
  8.  *
  9.  * This file is distributed in the hope that it will be useful,but without any
  10.  * warranty.  No author or distributor accepts responsibility to anyone for
  11.  * the consequences of using it or for whether it serves any particular
  12.  * purpose or works at all. 
  13.  *
  14.  *
  15.  * Everyone is granted permission to copy, modify and redistribute this file
  16.  * under the following conditions: 
  17.  *
  18.  * Permission is granted to anyone to make or distribute copies of the source
  19.  * code, either as received or modified, in any medium, provided that all
  20.  * copyright notices, permission and nonwarranty notices are preserved, and
  21.  * that the distributor grants the recipient permission for further
  22.  * redistribution as permitted by this document. 
  23.  *
  24.  * No part of this program can be used in any commercial product. 
  25.  */
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #include <windows.h>
  33. #include <commdlg.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include <dos.h>
  38. #include <math.h>
  39.  
  40. #include "definiti.h"
  41.  
  42.  
  43.  
  44.  
  45. int             xClient = 550, yClient = 400;
  46. int             xStart = 0, yStart = 0;
  47.  
  48.  
  49.  
  50. HANDLE          hInst;        /* hInstance of application */
  51. HWND            hWndMain;    /* hWnd of main window */
  52.  
  53. HWND  DialogWinHandle;
  54.  
  55.  
  56.  
  57. static char     AppName[20];    /* name of application */
  58.  
  59. /* at the beginning */
  60. int             WhiteBallOut = NO;
  61. int             BlackBallOut = NO;
  62.  
  63. int             YourScore = 0, MyScore = 0;
  64. /* these are for stick position */
  65. int             StartX, StartY, NewX, NewY;
  66.  
  67. Space           PlayGround={72.0,42.0,510.0,320.0};
  68.  
  69. Timing          PlayTime;
  70.  
  71. /* this is the big guy, controlling everything */
  72. Coordinator    *Dept_Head;
  73.  
  74. Stick          *PoolStick;
  75. Stick          *Trajectory;
  76.  
  77. Ball           *WhiteBall, *BlackBall;
  78. Ball           *DottedWhiteBall;/* we'll use it for 3-ball pool */
  79. Ball           *MyBalls[7];
  80. Ball           *YourBalls[7];
  81.  
  82. int             gameType, HowManyBalls;
  83. extern int      WantsTrajectory;
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. int             WLeft = 10, WTop = 10, WRight = 550, WBottom = 400;
  93. int             TableTop = 20, TableLeft = 50;
  94. int             PocDiameter = 40;
  95. int             MouseX, MouseY;
  96. int             LeftButton = FALSE;
  97. int             PressedBefore = FALSE;
  98. int             MouseMessage = FALSE;
  99.  
  100. HPEN            StickPen;
  101. HPEN            TrajPen;
  102. Stick          *PoolStick;
  103. Stick          *Trajectory;
  104.  
  105.  
  106. HBITMAP         MyBitmapHandle;
  107. HBITMAP         BallDel, Balls[16];
  108. HDC             hDCBall[16];
  109. HDC             hDCBallDel;
  110.  
  111. BITMAP          BitmapDim;
  112.  
  113.  
  114.  
  115.  
  116. HBRUSH          hbrTable, hbrPocket, hbrSurface;
  117. HPEN            hpenBorder, hpenSurBorder;
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. int             PASCAL
  125. WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  126.     LPSTR lpszCmdLine, int cmdShow);
  127.  
  128. void
  129. InitApp(HANDLE hInstance, HANDLE hPrevInstance,
  130.     LPSTR lpszCmdLine, int cmdShow);
  131.  
  132.  
  133.  
  134. long FAR        PASCAL
  135. AppWndProc(HWND hWnd, WORD message,
  136.        WORD wParam, LONG lParam);
  137.  
  138. void
  139. BuildTheTable(HDC hDC);
  140.  
  141. void
  142. MoveTheBall(HDC hdc);
  143.  
  144.  
  145. void
  146. LayTheFloor(HDC hdc);
  147. extern Stick   *
  148. new__Stick(int type);
  149.  
  150.  
  151.  
  152.  
  153. extern int      oldx, oldy, oldxx, oldyy;
  154. extern int      ButtonPressedBefore;
  155. extern int      pane_x, pane_y;
  156. extern 
  157. handle_stick(HDC hdc, int button);
  158. extern void 
  159. handle_white_ball(HDC hdc, int button);
  160.  
  161. extern void     MainSetup();
  162.  
  163.  
  164. /* file open dialog */
  165. char            szDirName[256];
  166. char            szFile[256], szFileTitle[256];
  167. UINT            i, cbString;
  168. char            chReplace;    /* string separator for szFilter */
  169. char            szFilter[256];
  170. HFILE           hf;
  171. OPENFILENAME    ofn;
  172. FILE *filehandle;
  173.  
  174.  
  175. extern BOOL FAR PASCAL 
  176. PlayersHandleDlgProc(HWND hDlg, WORD iMessage, WORD wParam, LONG lParam);
  177. extern int 
  178. GetPlayersName(HANDLE hinst, HWND hwnd);
  179.  
  180. extern TwoPlayer My;
  181.  
  182.  
  183. extern BOOL FAR PASCAL
  184. ScoresHandleDlgProc(HWND hDlg, WORD iMessage, WORD wParam, LONG lParam);
  185. extern int
  186. GetScores(HANDLE hinst, HWND hwnd);
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198. int             PASCAL
  199. WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  200.     LPSTR lpszCmdLine, int cmdShow)
  201. {
  202.     MSG             msg;
  203.     /* this is the name of the application */
  204.     strcpy(AppName, "Win Pool");
  205.  
  206.     hInst = hInstance;    /* init this application. */
  207.     InitApp(hInstance, hPrevInstance, lpszCmdLine, cmdShow);
  208.  
  209.     /* Get and dispatch messages for this applicaton. */
  210.  
  211.     while (GetMessage(&msg, NULL, 0, 0)) {
  212.      if(DialogWinHandle==NULL || !IsDialogMessage(DialogWinHandle,&msg)){
  213.  
  214.         TranslateMessage(&msg);
  215.         DispatchMessage(&msg);
  216.             }
  217.     }
  218.  
  219.  
  220.     return (msg.wParam);
  221. }
  222.  
  223.  
  224.  
  225. void
  226. InitApp(HANDLE hInstance, HANDLE hPrevInstance,
  227.     LPSTR lpszCmdLine, int cmdShow)
  228. {
  229.     WNDCLASS        wcAppClass;
  230.  
  231.     if (!hPrevInstance) {    /* if no previous instance, this is first */
  232.         /* Define the window class for this application. */
  233.         wcAppClass.lpszClassName = (LPSTR) AppName;
  234.         wcAppClass.hInstance = hInstance;
  235.         wcAppClass.lpfnWndProc = AppWndProc;
  236.         wcAppClass.hCursor = LoadCursor(NULL, IDC_ARROW);
  237.         wcAppClass.hIcon = LoadIcon(hInstance, "Pool");
  238.         wcAppClass.lpszMenuName = NULL ;  /*"POOL";   */
  239.         wcAppClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  240.         wcAppClass.style = CS_HREDRAW | CS_VREDRAW;
  241.         wcAppClass.cbClsExtra = 0;
  242.         wcAppClass.cbWndExtra = 0;
  243.  
  244.         /* Register the class */
  245.         RegisterClass(&wcAppClass);
  246.     }
  247.     /* Create applications main window. */
  248.     hWndMain = CreateWindowEx(0L,
  249.                 AppName,
  250.                 AppName,
  251.                 WS_OVERLAPPEDWINDOW,
  252.                 CW_USEDEFAULT,
  253.                 0,
  254.                 550,
  255.                 410,
  256.                 NULL,
  257.                 NULL,
  258.                 hInstance,
  259.                 NULL
  260.         );
  261.  
  262.     /* Update display of main window. */
  263.     ShowWindow(hWndMain, cmdShow);
  264.     UpdateWindow(hWndMain);
  265. }
  266.  
  267.  
  268. float           XXX, YYY;
  269. int             tx, ty;
  270. LPARAM          lParaM;
  271.  
  272.     FARPROC         lpfnHandleDlgProc;
  273.  
  274.  
  275.       extern    BOOL FAR PASCAL FloatHandleDlgProc(HWND hDlg, WORD iMessage, WORD wParam, LONG lParam);
  276.  
  277.  
  278.  
  279.  
  280.  
  281. long FAR        PASCAL
  282. AppWndProc(HWND hWnd, WORD message,
  283.        WORD wParam, LONG lParam)
  284. {
  285.     HDC             hDC;
  286.     PAINTSTRUCT     ps;
  287.     int             i;
  288.  
  289.  
  290.  
  291.     switch (message) {
  292.  
  293.  
  294.  
  295.     case WM_CREATE:
  296.  
  297.  
  298.     lpfnHandleDlgProc = MakeProcInstance(FloatHandleDlgProc, hInst);
  299.  
  300.     DialogWinHandle = CreateDialog(hInst, "FLOATDIALOG", hWnd, lpfnHandleDlgProc);
  301.  
  302.      ShowWindow(DialogWinHandle,SW_SHOW);
  303.  
  304.  
  305.  
  306.         strcpy(My.Player1String, "Player I");
  307.         strcpy(My.Player2String, "Player II");
  308.  
  309.  
  310.         MainSetup();
  311.  
  312.  
  313.         hDC = GetDC(hWnd);
  314.  
  315.         PoolStick = new__Stick(STICK);
  316.         Trajectory = new__Stick(TRAJECTORY);
  317.  
  318.         MyBitmapHandle = LoadBitmap(hInst, "Tile");
  319.  
  320.         BallDel = LoadBitmap(hInst, "BALLDEL");
  321.         hDCBallDel = CreateCompatibleDC(hDC);
  322.         SelectObject(hDCBallDel, BallDel);
  323.  
  324.         /* load other bitmaps here too */
  325.         Balls[0] = LoadBitmap(hInst, "BALL0");
  326.         Balls[1] = LoadBitmap(hInst, "BALL8");
  327.         Balls[2] = LoadBitmap(hInst, "BALL2");
  328.         Balls[3] = LoadBitmap(hInst, "BALL3");
  329.         Balls[4] = LoadBitmap(hInst, "BALL4");
  330.         Balls[5] = LoadBitmap(hInst, "BALL5");
  331.         Balls[6] = LoadBitmap(hInst, "BALL6");
  332.         Balls[7] = LoadBitmap(hInst, "BALL7");
  333.         Balls[8] = LoadBitmap(hInst, "BALL1");
  334.         Balls[9] = LoadBitmap(hInst, "BALL9");
  335.         Balls[10] = LoadBitmap(hInst, "BALL10");
  336.         Balls[11] = LoadBitmap(hInst, "BALL11");
  337.         Balls[12] = LoadBitmap(hInst, "BALL12");
  338.         Balls[13] = LoadBitmap(hInst, "BALL13");
  339.         Balls[14] = LoadBitmap(hInst, "BALL14");
  340.         Balls[15] = LoadBitmap(hInst, "BALL15");
  341.  
  342.  
  343.  
  344.         /* create space to put bitmaps */
  345.         for (i = 0; i < 16; i++) {
  346.             hDCBall[i] = CreateCompatibleDC(hDC);
  347.             SelectObject(hDCBall[i], Balls[i]);
  348.  
  349.         }
  350.  
  351.         /* get the size of a bitmap */
  352.         GetObject(Balls[1], sizeof(BITMAP), &BitmapDim);
  353.  
  354.  
  355.  
  356.         StickPen = CreatePen(PS_SOLID, 3, RGB(255, 255, 255));
  357.         TrajPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
  358.  
  359.  
  360.         /* trying to get blue */
  361.         hbrTable = CreateSolidBrush(RGB(0, 126, 255));
  362.         hpenBorder = CreatePen(PS_SOLID, 6, RGB(255, 0, 0));
  363.  
  364.         /* let's change the brush */
  365.         hbrPocket = CreateSolidBrush(RGB(0, 0, 0));
  366.  
  367.         hbrSurface = CreateSolidBrush(RGB(0, 0, 255));
  368.  
  369.         hpenSurBorder = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  370.  
  371.  
  372.  
  373.         /*
  374.          * PoolTable.left = TableLeft; PoolTable.top  = TableTop;
  375.          * PoolTable.bottom = WRight-20; PoolTable.right =
  376.          * WBottom-20; 
  377.          *
  378.          */
  379.         Dept_Head->InitConfig(Dept_Head, hDC);
  380.  
  381.         ReleaseDC(hWnd, hDC);
  382.  
  383.         break;
  384.  
  385.  
  386.  
  387.     case WM_PAINT:
  388.  
  389.  
  390.         BeginPaint(hWnd, (LPPAINTSTRUCT) & ps);
  391.         hDC = ps.hdc;
  392.         BuildTheTable(hDC);
  393.  
  394.         for (i = 0; i < Dept_Head->NumberOfObjects; i++)
  395.             Dept_Head->Objects[i]->ShowOut = NO;
  396.         Dept_Head->ShowStaticPosition(Dept_Head, hDC);
  397.  
  398.  
  399.  
  400.         EndPaint(hWnd, (LPPAINTSTRUCT) & ps);
  401.         break;
  402.  
  403.     case WM_LBUTTONDOWN:
  404.  
  405.                 SetCapture(hWnd);
  406.         break;
  407.  
  408.     case WM_MOUSEMOVE:
  409.  
  410.         /* case WM_LBUTTONDOWN : */
  411.  
  412.         pane_x = (int) LOWORD(lParam);
  413.         pane_y = (int) HIWORD(lParam);
  414.         lParaM = lParam;
  415.  
  416.         if (wParam == MK_LBUTTON)
  417.             LeftButton = TRUE;
  418.         else
  419.             LeftButton = FALSE;
  420.  
  421.  
  422.         hDC = GetDC(hWnd);
  423.         tx = abs(pane_x - (int) Dept_Head->Objects[0]->CurrentL.x);
  424.         ty = abs(pane_y - (int) Dept_Head->Objects[0]->CurrentL.y);
  425.  
  426.  
  427.         XXX = tx * tx;
  428.         YYY = ty * ty;
  429.  
  430.  
  431.  
  432.         /* let's see what the hell player wants to do.. */
  433.         if ((tx < Dept_Head->Objects[0]->radius) && (ty < Dept_Head->Objects[0]->radius))
  434.             handle_white_ball(hDC, LeftButton);    /* wants to move the
  435.                                  * white ball */
  436.         else
  437.             handle_stick(hDC, LeftButton);    /* wants to move stick */
  438.         /*
  439.          * note that if you move your mouse fast, blt will not be
  440.          * able to catch up with you, so you are gonna end up moving
  441.          * the stick not the white ball. 
  442.          */
  443.         ReleaseDC(hWnd, hDC);
  444.  
  445.  
  446.  
  447.         break;
  448.  
  449.  
  450.     case WM_LBUTTONUP:
  451.  
  452.         if (ButtonPressedBefore)
  453.             SendMessage(hWnd, WM_MOUSEMOVE, 0, lParaM);
  454.                 ReleaseCapture();
  455.         break;
  456.  
  457.  
  458.     case WM_SIZE:
  459.  
  460.         /* Save size of window client area. */
  461.         if (lParam) {
  462.             yClient = HIWORD(lParam);
  463.             xClient = LOWORD(lParam);
  464.         }
  465.     case WM_COMMAND:
  466.  
  467.         switch (wParam) {
  468.  
  469.         case NewGame:
  470.  
  471.             hDC = GetDC(hWnd);
  472.             BuildTheTable(hDC);
  473.             Dept_Head->InitConfig(Dept_Head, hDC);
  474.             ReleaseDC(hWnd, hDC);
  475.             /* to delete balls at the outside */
  476.             /* SendMessage(hWnd,WM_PAINT,0,0L); */
  477.  
  478.             break;
  479.  
  480.  
  481.  
  482.         case LoadGame:
  483.  
  484.  
  485.             /*
  486.              * Get the system directory name, and store in
  487.              * szDirName 
  488.              */
  489.             GetSystemDirectory(szDirName, sizeof(szDirName));
  490.             szFile[0] = '\0';
  491.             if ((cbString = LoadString(hInst, IDS_FILTERSTRING,
  492.                     szFilter, sizeof(szFilter))) == 0) {
  493.  
  494.                 MessageBox(hWnd, "Can't Read Resources!...\nAborting... ", "Error", MB_OK);
  495.  
  496.                 return 0L;
  497.             }
  498.             chReplace = szFilter[cbString - 1];    /* retrieve wildcard */
  499.             for (i = 0; szFilter[i] != '\0'; i++) {
  500.                 if (szFilter[i] == chReplace)
  501.                     szFilter[i] = '\0';
  502.             }
  503.             /* Set all structure members to zero. */
  504.             memset(&ofn, 0, sizeof(OPENFILENAME));
  505.             ofn.lStructSize = sizeof(OPENFILENAME);
  506.             ofn.hwndOwner = hWnd;
  507.             ofn.lpstrFilter = szFilter;
  508.             ofn.nFilterIndex = 1;
  509.             ofn.lpstrFile = szFile;
  510.             ofn.nMaxFile = sizeof(szFile);
  511.             ofn.lpstrFileTitle = szFileTitle;
  512.             ofn.nMaxFileTitle = sizeof(szFileTitle);
  513.             ofn.lpstrInitialDir = szDirName;
  514.             ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  515.             if (GetOpenFileName(&ofn)) {
  516.  
  517.                  if ((filehandle = fopen(ofn.lpstrFile,"r"))==NULL)
  518.                     MessageBox(hWnd, "Can't Read From a File!...\nAborting...", "Error", MB_OK);
  519.                  else
  520.                     fscanf(filehandle,"%s  %s  %d  %d",My.Player1String,My.Player2String,&My.Player1Score,&My.Player2Score);
  521.  
  522.                    close(filehandle);
  523.  
  524.             } else
  525.                  ;  //    MessageBox(hWnd, "Can't Open File To Read!...\nAborting...", "Error", MB_OK);
  526.  
  527.             break;
  528.             /* Fileopen */
  529.  
  530.         case SaveIt:
  531.  
  532.             /*
  533.              * Get the system directory name, and store in
  534.              * szDirName
  535.              */
  536.             GetSystemDirectory(szDirName, sizeof(szDirName));
  537.             szFile[0] = '\0';
  538.             if ((cbString = LoadString(hInst, IDS_FILTERSTRING,
  539.                     szFilter, sizeof(szFilter))) == 0) {
  540.  
  541.                 MessageBox(hWnd, "Can't Read Resources!...\nAborting... ", "Error", MB_OK);
  542.  
  543.                 return 0L;
  544.             }
  545.             chReplace = szFilter[cbString - 1];    /* retrieve wildcard */
  546.             for (i = 0; szFilter[i] != '\0'; i++) {
  547.                 if (szFilter[i] == chReplace)
  548.                     szFilter[i] = '\0';
  549.             }
  550.             /* Set all structure members to zero. */
  551.             memset(&ofn, 0, sizeof(OPENFILENAME));
  552.             ofn.lStructSize = sizeof(OPENFILENAME);
  553.             ofn.hwndOwner = hWnd;
  554.             ofn.lpstrFilter = szFilter;
  555.             ofn.nFilterIndex = 1;
  556.             ofn.lpstrFile = szFile;
  557.             ofn.nMaxFile = sizeof(szFile);
  558.             ofn.lpstrFileTitle = szFileTitle;
  559.             ofn.nMaxFileTitle = sizeof(szFileTitle);
  560.             ofn.lpstrInitialDir = szDirName;
  561.             ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
  562.             if (GetSaveFileName(&ofn)) {
  563.  
  564.  
  565.                 if ((filehandle = fopen(ofn.lpstrFile,"w"))==NULL)
  566.                     MessageBox(hWnd, "Can't Read From a File!...\nAborting...", "Error", MB_OK);
  567.                  else
  568.                     fprintf(filehandle,"%s  %s  %d  %d",My.Player1String,My.Player2String,My.Player1Score,My.Player2Score);
  569.  
  570.                    close(filehandle);
  571.  
  572.             } else
  573.                   ; //    MessageBox(hWnd, "Can't Open File To Save!...\nAborting...", "Error", MB_OK);
  574.  
  575.  
  576.  
  577.  
  578.  
  579.  
  580.             break;
  581.  
  582.  
  583.         case Players:
  584.  
  585.             GetPlayersName(hInst, hWnd);
  586.  
  587.             break;
  588.  
  589.  
  590.         case Scores:
  591.  
  592.             GetScores(hInst, hWnd);
  593.  
  594.             break;
  595.  
  596.  
  597.  
  598.  
  599.         case TrajectoryMode:
  600.             WantsTrajectory = !WantsTrajectory;
  601.  
  602.             if (WantsTrajectory == YES)
  603.                 CheckMenuItem(GetMenu(hWnd), TrajectoryMode, MF_CHECKED);
  604.             else
  605.                 CheckMenuItem(GetMenu(hWnd), TrajectoryMode, MF_UNCHECKED);
  606.  
  607.  
  608.             break;
  609.  
  610.  
  611.         case ExitThisApp:
  612.             /* User selected Quit on menu */
  613.             PostMessage(hWnd, WM_CLOSE, 0, 0L);
  614.  
  615.             break;
  616.  
  617.         case AboutBox:
  618.             MessageBox(hWnd,
  619.                    "Win Pool 1992 Version 1.0\nCopyright Ismail ARIT\nKusadasi,AYDIN,TURKIYE. 09400\n(Please read 'readme.txt or readme.wri'\nfor more info...)\n",
  620.                    "About ",
  621.                    MB_OK | MB_ICONINFORMATION);
  622.             break;
  623.  
  624.  
  625.  
  626.         default:
  627.             break;
  628.         }
  629.         break;
  630.  
  631.     case WM_DESTROY:
  632.         for (i = 0; i < 16; i++)
  633.             DeleteDC(hDCBall[i]);
  634.  
  635.         /* This is the end if we were closed by a DestroyWindow call. */
  636.         PostQuitMessage(0);    /* this is the end...     */
  637.         break;
  638.  
  639.     case WM_CLOSE:
  640.         /* Tell windows to destroy our window. */
  641.         FreeProcInstance(lpfnHandleDlgProc);
  642.  
  643.         DestroyWindow(hWnd);
  644.         break;
  645.  
  646.     default:
  647.         /* Let windows handle all messages we choose to ignore. */
  648.         return (DefWindowProc(hWnd, message, wParam, lParam));
  649.     }
  650.  
  651.     return (0L);
  652. }
  653.  
  654.  
  655.  
  656.  
  657. void
  658. LayTheFloor(HDC hdc)
  659. {
  660.     /* hInst is the handle for this instance */
  661.     HDC             hDCMem;
  662.     BITMAP         *MyBitmap;
  663.     POINT           Original, Normal;
  664.  
  665.     hDCMem = CreateCompatibleDC(hdc);
  666.     SelectObject(hDCMem, MyBitmapHandle);
  667.     SetMapMode(hDCMem, GetMapMode(hdc));
  668.  
  669.     GetObject(MyBitmapHandle, sizeof(BITMAP), (LPSTR) MyBitmap);
  670.     Normal.x = MyBitmap->bmWidth;
  671.     Normal.y = MyBitmap->bmHeight;
  672.     DPtoLP(hdc, &Normal, 1);
  673.  
  674.     Original.x = 0;
  675.     Original.y = 0;
  676.  
  677.     DPtoLP(hDCMem, &Original, 1);
  678.  
  679.  
  680.  
  681.     StretchBlt(hdc, xStart, yStart, xClient, yClient,
  682.            hDCMem, Original.x, Original.y, Normal.x,
  683.            Normal.y, SRCCOPY);
  684.  
  685.     DeleteDC(hDCMem);
  686.  
  687.  
  688. }
  689.  
  690. void
  691. MoveTheBall(HDC hdc)
  692. {
  693.  
  694.     int             i;
  695.     long            j;
  696.     float           s;
  697.  
  698.     for (i = 0; i < 400; i += 20) {
  699.         /*
  700.          *
  701.          * BitBlt(hdc,i+100,200,BitmapDim.bmWidth,BitmapDim.bmHeight,h
  702.          * DCBallDel, 0,0,SRCCOPY); 
  703.          */
  704.  
  705.  
  706.         for (j = 0; j < 16; j++)
  707.             BitBlt(hdc, i + 100, 50 + j * 16, BitmapDim.bmWidth, BitmapDim.bmHeight, hDCBall[j],
  708.                    0, 0, SRCCOPY);
  709.  
  710.  
  711.  
  712.     }
  713.  
  714.  
  715. };
  716.  
  717. void
  718. BuildTheTable(HDC hDC)
  719. {
  720.  
  721.  
  722.     HPEN            hpenOld;
  723.     HBRUSH          hbrOld;
  724.  
  725.  
  726.     RECT            PoolTable, PoolSurface, TopLeftPoc, TopRightPoc, TopMiddlePoc, BottomLeftPoc, BottomRightPoc, BottomMiddlePoc;
  727.  
  728.  
  729.  
  730.  
  731.     PoolTable.left = TableLeft;
  732.     PoolTable.top = TableTop;
  733.     PoolTable.bottom = WBottom - 60;
  734.     PoolTable.right = WRight - 20;
  735.  
  736.     PoolSurface.left = PoolTable.left + PocDiameter / 2;
  737.     PoolSurface.top = PoolTable.top + PocDiameter / 2;
  738.     PoolSurface.bottom = PoolTable.bottom - PocDiameter / 2;
  739.     PoolSurface.right = PoolTable.right - PocDiameter / 2;
  740.  
  741.  
  742.     /* first lay the floor */
  743.     LayTheFloor(hDC);
  744.  
  745.  
  746.  
  747.     hbrOld = SelectObject(hDC, hbrTable);
  748.     /* let's create the table corners */
  749.     FillRect(hDC, (RECT FAR *) & PoolTable, hbrTable);
  750.  
  751.  
  752.     hpenOld = SelectObject(hDC, hpenBorder);
  753.     /* let's draw the borders */
  754.     Rectangle(hDC, PoolTable.left, PoolTable.top,
  755.           PoolTable.right, PoolTable.bottom);
  756.  
  757.  
  758.     SelectObject(hDC, hbrPocket);
  759.  
  760.     BottomLeftPoc.left = PoolTable.left;
  761.     BottomLeftPoc.top = PoolTable.bottom - PocDiameter;
  762.     BottomLeftPoc.right = PoolTable.left + PocDiameter;
  763.     BottomLeftPoc.bottom = PoolTable.bottom;
  764.     Ellipse(hDC, BottomLeftPoc.left, BottomLeftPoc.top,
  765.         BottomLeftPoc.right, BottomLeftPoc.bottom);
  766.  
  767.  
  768.     BottomRightPoc.left = PoolTable.right - PocDiameter;
  769.     BottomRightPoc.top = PoolTable.bottom - PocDiameter;
  770.     BottomRightPoc.right = PoolTable.right;
  771.     BottomRightPoc.bottom = PoolTable.bottom;
  772.     Ellipse(hDC, BottomRightPoc.left, BottomRightPoc.top,
  773.         BottomRightPoc.right, BottomRightPoc.bottom);
  774.  
  775.  
  776.     BottomMiddlePoc.left = PoolTable.left + ((PoolTable.right - PoolTable.left) - PocDiameter) / 2;
  777.     BottomMiddlePoc.top = PoolTable.bottom - PocDiameter;
  778.     BottomMiddlePoc.right = PoolTable.left + ((PoolTable.right - PoolTable.left) + PocDiameter) / 2;
  779.     BottomMiddlePoc.bottom = PoolTable.bottom;
  780.     Ellipse(hDC, BottomMiddlePoc.left, BottomMiddlePoc.top,
  781.         BottomMiddlePoc.right, BottomMiddlePoc.bottom);
  782.  
  783.  
  784.     TopLeftPoc.left = PoolTable.left;
  785.     TopLeftPoc.top = PoolTable.top;
  786.     TopLeftPoc.right = PoolTable.left + PocDiameter;
  787.     TopLeftPoc.bottom = PoolTable.top + PocDiameter;
  788.     Ellipse(hDC, TopLeftPoc.left, TopLeftPoc.top,
  789.         TopLeftPoc.right, TopLeftPoc.bottom);
  790.  
  791.  
  792.     TopRightPoc.left = PoolTable.right - PocDiameter;
  793.     TopRightPoc.top = PoolTable.top;
  794.     TopRightPoc.right = PoolTable.right;
  795.     TopRightPoc.bottom = PoolTable.top + PocDiameter;
  796.     Ellipse(hDC, TopRightPoc.left, TopRightPoc.top,
  797.         TopRightPoc.right, TopRightPoc.bottom);
  798.  
  799.  
  800.     TopMiddlePoc.left = PoolTable.left + ((PoolTable.right - PoolTable.left) - PocDiameter) / 2;
  801.     TopMiddlePoc.top = PoolTable.top;
  802.     TopMiddlePoc.right = PoolTable.left + ((PoolTable.right - PoolTable.left) + PocDiameter) / 2;
  803.     TopMiddlePoc.bottom = PoolTable.top + PocDiameter;
  804.     Ellipse(hDC, TopMiddlePoc.left, TopMiddlePoc.top,
  805.         TopMiddlePoc.right, TopMiddlePoc.bottom);
  806.  
  807.  
  808.     SelectObject(hDC, hbrSurface);
  809.     FillRect(hDC, (RECT FAR *) & PoolSurface, hbrSurface);
  810.  
  811.  
  812.     SelectObject(hDC, hpenSurBorder);
  813.     /* let's draw the borders for surface */
  814.     Rectangle(hDC, PoolSurface.left, PoolSurface.top,
  815.           PoolSurface.right, PoolSurface.bottom);
  816.  
  817.     /* let's restore the original pen and brush here */
  818.     SelectObject(hDC, hpenOld);
  819.     SelectObject(hDC, hbrOld);
  820.  
  821.  
  822.  
  823. };
  824.