home *** CD-ROM | disk | FTP | other *** search
/ Solo Programadores 22 / SOLO_22.iso / packages / win32ada / data.z / BOUNCE.ADB < prev    next >
Encoding:
Text File  |  1995-12-19  |  19.9 KB  |  646 lines

  1. -- $Source: /home/harp/1/proto/monoBANK/winnt/bounce.adb,v $ 
  2. -- $Revision: 1.3 $ $Date: 95/12/18 19:44:17 $ $Author: mg $ 
  3. -- $Id: bounce.adb 1.2 1995/01/25 13:52:02 teg Exp teg $
  4.  
  5. with Win32;
  6. with Win32.WinDef;
  7. with Win32.WinUser;
  8. with Win32.WinGdi;
  9. with Win32.WinBase;
  10.  
  11. with Gdidemo_Util;
  12. with Wininfo;
  13. with Unchecked_Conversion;
  14. with Convert;
  15.  
  16. --  Interfaces.C included only to get visibility to type operations
  17. with Interfaces.C;   use Interfaces.C;
  18.  
  19. with Interfaces.C.Strings; use Interfaces.C.Strings;
  20.  
  21. package body Bounce is
  22.  
  23.   use type System.Address;
  24.   use type Win32.BOOL;
  25.  
  26.   -- Used in CreateBounceWindow
  27.   mcs         : aliased Win32.WinUser.MDICREATESTRUCT;
  28.  
  29.   -- Used in BouncePaintProc
  30.   ps          : aliased Win32.WinUser.PAINTSTRUCT;
  31.  
  32.   -- Used in BounceRefresh
  33.   rect_p      : aliased Win32.WinDef.RECT;
  34.   pDimensions : aliased Win32.WinDef.POINT;
  35.  
  36.   -- Used in CheckEdgePostion
  37.   pPos,
  38.   pDir,
  39.   pDim        : aliased Win32.WinDef.POINT;
  40.   rect_p2     : aliased Win32.Windef.RECT;
  41.   
  42.   -- Used in ballBounce
  43.   pOrg,
  44.   pExt        : aliased Win32.WinDef.POINT;
  45.  
  46.   -- Used in ballGetPosition
  47.   pOrg2       : aliased Win32.WinDef.POINT;
  48.  
  49.  
  50.   -- Dummy function return values
  51.   bResult : Win32.BOOL;
  52.   iResult : Win32.INT;
  53.   uResult : Win32.UINT;
  54.   hlResult : Win32.Windef.HLOCAL;
  55.   lreturn  : Win32.LRESULT;
  56.  
  57.   -- Local functions to this package body
  58.   procedure XFormClear (XForm : in out MYXFORM);
  59.   procedure XFormScale (XForm : in out MYXFORM;
  60.                         xScale, yScale : Win32.LONG);
  61.   procedure XFormTrans (XForm : in out MYXFORM;
  62.                         xTrans, yTrans : Win32.LONG);
  63.   procedure XFormPoint (XForm : MYXFORM;
  64.                         Point : in out Win32.WinDef.POINT);
  65.  
  66.   -- Unchecked conversion utility functions
  67.   function HANDLE_TO_PBD is new Unchecked_Conversion (Win32.Winnt.HANDLE,
  68.                                                       PBOUNCEDATA);
  69.   function LPVOID_TO_PBALLDATA is new Unchecked_Conversion (Win32.LPVOID,
  70.                                                             PBALLDATA);
  71.  
  72. -- | CREATE BOUNCE WINDOW PROCEDURE
  73. procedure CreateBounceWindow (hWndClient : Win32.WinDef.HWND;
  74.                               nItem      : Win32.INT) is
  75.   hInst_p : Win32.Winnt.HANDLE;
  76.   mcs_p   : Win32.WinUser.LPMDICREATESTRUCT;
  77. begin
  78.  
  79.   hInst_p := Gdidemo_Util.GETINSTANCE (hWndClient);
  80.  
  81.   --  Initialize the MDI create struct for creation of the
  82.   --  test window.
  83.   mcs.szClass := BOUNCECLASS;
  84.   mcs.szTitle := BOUNCETITLE;
  85.   mcs.hOwner  := hInst_p;
  86.   mcs.x       := Win32.WinUser.CW_USEDEFAULT;
  87.   mcs.y       := Win32.WinUser.CW_USEDEFAULT;
  88.   mcs.cx      := Win32.WinUser.CW_USEDEFAULT;
  89.   mcs.cy      := Win32.WinUser.CW_USEDEFAULT;
  90.   mcs.style   := 0;
  91.   mcs.lParam  := Win32.LPARAM (nItem);
  92.  
  93.   mcs_p := mcs'Access;
  94.  
  95.   lreturn := Win32.WinUser.SendMessage
  96.                                 (hWndClient,
  97.                                  Win32.WinUser.WM_MDICREATE,
  98.                                  0,
  99.                                  Convert.LPMDICREATESTRUCT_TO_LPARAM (mcs_p));
  100.  
  101. end CreateBounceWindow;
  102.  
  103. -- |
  104. -- | BOUNCE WINDOW PROCEDURE
  105. -- | The callback procedure supplied.
  106. function BounceProc (hWnd_p   : Win32.WinDef.HWND;
  107.                      wMsg     : Win32.UINT;
  108.                      wParam_p : Win32.WPARAM;
  109.                      lParam_p : Win32.LPARAM) return Win32.LRESULT is
  110. begin
  111.   case wMsg is
  112.     when Win32.WinUser.WM_CREATE =>
  113.       bResult := BounceCreateProc(hWnd_p);
  114.  
  115.     when Win32.WinUser.WM_MOVE =>
  116.       BounceRefresh(hWnd_p);
  117.  
  118.     when Win32.WinUser.WM_COMMAND =>
  119.       bResult := BounceCommandProc(hWnd_p,wParam_p,lParam_p);
  120.  
  121.     when Win32.WinUser.WM_TIMER =>
  122.       BounceObjects(hWnd_p);
  123.  
  124.     when Win32.WinUser.WM_PAINT =>
  125.       BouncePaintProc(hWnd_p);
  126.  
  127.     when Win32.WinUser.WM_DESTROY =>
  128.       BounceDestroyProc(hWnd_p);
  129.  
  130.     when others =>
  131.       return Win32.WinUser.DefMDIChildProc (hWnd_p, wMsg, wParam_p, lParam_p);
  132.  
  133.   end case;
  134.  
  135.   return Win32.LRESULT (0);
  136.  
  137. end BounceProc; 
  138.  
  139.  
  140. -- | BOUNCE CREATE PROCEDURE
  141. -- |
  142. function BounceCreateProc (hWnd_p : Win32.WinDef.HWND) return Win32.BOOL is
  143.   pbd : PBOUNCEDATA; -- := new BOUNCEDATA; note that we don't have to do 'new'
  144.   pbd_handle : Win32.Winnt.HANDLE;
  145. begin
  146.   if WinInfo.AllocWindowInfo (hWnd_p, (BOUNCEDATA'size / 8)) = 
  147.     Win32.TRUE then
  148.     pbd_handle := WinInfo.LockWindowInfo (hWnd_p);
  149.     if pbd_handle /= System.Null_Address then  
  150.       pbd := HANDLE_TO_PBD (pbd_handle); 
  151.       pbd.hBall1 := ballCreate (hWnd_p, 20, 20, 
  152.                                   Win32.WinGdi.RGB (255,0,0));
  153.       pbd.hBall2 := ballCreate (hWnd_p, 20, 20, 
  154.                                   Win32.WinGdi.RGB (0,0,255));
  155.       pbd.hBall3 := ballCreate (hWnd_p, 20, 20, 
  156.                                   Win32.WinGdi.RGB (0,255,0));
  157.       pbd.hBall4 := ballCreate (hWnd_p, 20, 20, 
  158.                                   Win32.WinGdi.RGB (255,0,255));
  159.       bResult := Wininfo.UnlockWindowInfo (hWnd_p);
  160.       uResult := Win32.WinUser.SetTimer (hWnd_p, 1, 50, null);
  161.       return Win32.TRUE;
  162.     end if;
  163.     bResult := Wininfo.FreeWindowInfo (hWnd_p);
  164.   end if;
  165.   return Win32.FALSE;
  166. end BounceCreateProc;
  167.  
  168.  
  169.  
  170. -- | BOUNCE COMMAND PROCEDURE
  171. -- |
  172. function BounceCommandProc (hWnd_p   : Win32.WinDef.HWND;
  173.                             wParam_p : Win32.WPARAM;
  174.                             lParam_p : Win32.LPARAM) return Win32.BOOL is
  175. begin
  176.   return Win32.TRUE;
  177. end BounceCommandProc; 
  178.  
  179.  
  180. -- | BOUNCE PAINT PROCEDURE
  181. -- |
  182. procedure BouncePaintProc (hWnd_p : Win32.WinDef.HWND) is
  183.   hDC_p : Win32.WinDef.HDC;
  184. begin
  185.   hDC_p := Win32.WinUser.BeginPaint (hWnd_p, ps'Access);
  186.   if hDC_p /= System.Null_Address then 
  187.     bResult := Win32.WinUser.EndPaint (hWnd_p, ps'Access);
  188.   end if;
  189.   BounceRefresh (hWnd_p);
  190.  
  191. end BouncePaintProc;
  192.  
  193.  
  194. -- | BOUNCE DESTROY PROCEDURE
  195. -- |
  196. procedure BounceDestroyProc (hWnd_p : Win32.WinDef.HWND) is
  197.   pbd : PBOUNCEDATA;
  198.   pbd_handle : Win32.Winnt.HANDLE;
  199. begin
  200.   bResult := Win32.WinUser.KillTimer (hWnd_p, 1);
  201.   pbd_handle := Wininfo.LockWindowInfo (hWnd_p);
  202.   if pbd_handle /= System.Null_Address then
  203.     pbd := HANDLE_TO_PBD (pbd_handle);
  204.     bResult := ballDestroy (pbd.hBall1);
  205.     bResult := ballDestroy (pbd.hBall2);
  206.     bResult := ballDestroy (pbd.hBall3);
  207.     bResult := ballDestroy (pbd.hBall4);
  208.     bResult := Wininfo.UnlockWindowInfo (hWnd_p);
  209.   end if;
  210.   bResult := Wininfo.FreeWindowInfo (hWnd_p);
  211.  
  212. end BounceDestroyProc;
  213.  
  214.  
  215. -- | BOUNCE REFRESH
  216. -- |
  217. procedure BounceRefresh (hWnd_p : Win32.WinDef.HWND) is
  218.   pbd         : PBOUNCEDATA;
  219.   pbd_handle  : Win32.Winnt.HANDLE;
  220.   hDC_p       : Win32.WinDef.HDC;
  221.   xDirection  : Win32.LONG;
  222.   yDirection  : Win32.LONG;
  223. begin
  224.   pbd_handle := Wininfo.LockWindowInfo (hWnd_p);
  225.   if pbd_handle /= System.Null_Address then
  226.     pbd := HANDLE_TO_PBD (pbd_handle);
  227.     hDC_p := Win32.WinUser.GetDc (hWnd_p);
  228.     if hDC_p /= System.Null_Address then
  229.       bResult := Win32.WinUser.GetClientRect(hWnd_p,rect_p'Access);
  230.       iResult := Win32.WinUser.FillRect
  231.                  (hDC_p,rect_p'Access,Gdidemo_Util.GETCLASSBRUSH(hWnd_p));
  232.       xDirection := (Gdidemo_util.lRandom rem 5) + 5;
  233.       yDirection := (Gdidemo_util.lRandom rem 5) + 5;
  234.       ballSetPosition(pbd.hBall1,0,0);
  235.       ballSetDirection(pbd.hBall1,xDirection,yDirection);
  236.       ballGetDimensions(pbd.hBall2,pDimensions);
  237.       ballSetPosition(pbd.hBall2,
  238.                       rect_p.right - pDimensions.x, 0);
  239.       xDirection := -1 * ((Gdidemo_Util.lRandom rem 5) + 5);
  240.       yDirection := (Gdidemo_Util.lRandom rem 5) + 5;
  241.       ballSetDirection(pbd.hBall2,xDirection,yDirection);
  242.       ballGetDimensions(pbd.hBall3, pDimensions);
  243.       ballSetPosition(pbd.hBall3, 0, (rect_p.bottom - pDimensions.y));
  244.       xDirection := (Gdidemo_Util.lRandom rem 5) + 5;
  245.       yDirection := -1 * ((Gdidemo_Util.lRandom rem 5) + 5);
  246.       ballSetDirection(pbd.hBall3, xDirection, yDirection);
  247.       ballGetDimensions(pbd.hBall4,pDimensions);
  248.       ballSetPosition(pbd.hBall4,
  249.                       rect_p.right - pDimensions.x,
  250.                       rect_p.bottom - pDimensions.y);
  251.       xDirection := -1 * ((Gdidemo_Util.lRandom rem 5) + 5);
  252.       yDirection := -1 * ((Gdidemo_Util.lRandom rem 5) + 5);
  253.       ballSetDirection(pbd.hBall4,xDirection,yDirection);
  254.  
  255.       ballBounce(pbd.hBall1);
  256.       ballBounce(pbd.hBall2);
  257.       ballBounce(pbd.hBall3);
  258.       ballBounce(pbd.hBall4);
  259.  
  260.       iResult := Win32.WinUser.ReleaseDC (hWnd_p, hDC_p);
  261.     end if;
  262.     bResult := Wininfo.UnlockWindowInfo (hWnd_p);
  263.   end if;    
  264. end BounceRefresh;
  265.  
  266.  
  267. procedure BounceObjects (hWnd_p : Win32.WinDef.HWND) is
  268.   pbd : PBOUNCEDATA; 
  269.   pbd_handle : Win32.Winnt.HANDLE;
  270. begin
  271.   pbd_handle := Wininfo.LockWindowInfo (hWnd_p);
  272.   if pbd_handle /= System.Null_Address then 
  273.     pbd := HANDLE_TO_PBD (pbd_handle);
  274.     --  /*
  275.     --  ** Determine if the balls hit any of the edges of the display.  If
  276.     --  ** they do, then these functions reset their position to something
  277.     --  ** more desireable and re-do their direction.
  278.     --  */
  279.     CheckEdgePosition(hWnd_p,pbd.hBall1);
  280.     CheckEdgePosition(hWnd_p,pbd.hBall2);
  281.     CheckEdgePosition(hWnd_p,pbd.hBall3);
  282.     CheckEdgePosition(hWnd_p,pbd.hBall4);
  283.  
  284.     ballBounce(pbd.hBall1);
  285.     ballBounce(pbd.hBall2);
  286.     ballBounce(pbd.hBall3);
  287.     ballBounce(pbd.hBall4);
  288.  
  289.     bResult := Wininfo.UnlockWindowInfo(hWnd_p);
  290.   end if;
  291. end BounceObjects;
  292.  
  293.  
  294. procedure CheckEdgePosition (hWnd_p : Win32.WinDef.HWND;
  295.                              hBall  : Win32.Winnt.HANDLE) is
  296.   xNewPos,yNewPos,xNewDir,yNewDir : Win32.LONG;
  297. begin
  298.   ballGetPosition(hBall,pPos);
  299.   ballGetDirection(hBall,pDir);
  300.   ballGetDimensions(hBall,pDim);
  301.  
  302.   bResult := Win32.WinUser.GetClientRect(hWnd_p,rect_p2'Access);
  303.  
  304.   -- /*
  305.   -- ** Check each edge of the client rectagle.  If the ball goes past the
  306.   -- ** boundries, reset the position and give it a new direction.
  307.   -- */
  308.   xNewDir := pDir.x;
  309.   yNewDir := pDir.y;
  310.   xNewPos := pPos.x + pDir.x;
  311.   yNewPos := pPos.y + pDir.y;
  312.  
  313.   if xNewPos < rect_p2.left then
  314.     xNewDir := (Gdidemo_Util.lRandom rem 5) + 5;
  315.     ballSetPosition (hBall,rect_p2.left,pPos.y);
  316.   end if;
  317.  
  318.   if (xNewPos + pDim.x) > rect_p2.right then
  319.     xNewDir := -1 * ((Gdidemo_Util.lRandom rem 5) + 5);
  320.     ballSetPosition(hBall, (rect_p2.right - pDim.x), pPos.y);
  321.   end if;
  322.  
  323.   if yNewPos < rect_p2.top then
  324.     yNewDir := (Gdidemo_Util.lRandom rem 5) + 5;
  325.     ballSetPosition(hBall,pPos.x,rect_p2.top);
  326.   end if;
  327.  
  328.   if (yNewPos + pDim.y) > rect_p2.bottom then
  329.     yNewDir := -1 * ((Gdidemo_Util.lRandom rem 5) + 5);
  330.     ballSetPosition(hBall, pPos.x, (rect_p2.bottom - pDim.y));
  331.   end if;
  332.  
  333.   ballSetDirection(hBall,xNewDir,yNewDir);
  334.  
  335. end CheckEdgePosition; 
  336.  
  337.  
  338. -- | CLEAR XFORM
  339. -- |
  340. procedure XFormClear (XForm : in out MYXFORM) is
  341.   Row,Col : Win32.INT;
  342. begin
  343.   for Row in 0 .. 2 loop
  344.     for Col in 0 .. 2 loop
  345.       if Row = Col then
  346.         XForm.xForm (Row,Col) := 1;
  347.       else
  348.         XForm.xForm (Row,Col) := 0;
  349.       end if;
  350.     end loop;
  351.   end loop;
  352. end XformClear;
  353.  
  354.  
  355. -- | XFORM SCALE
  356. -- |
  357. procedure XFormScale(XForm : in out MYXFORM;
  358.                      xScale : Win32.LONG;
  359.                      yScale : Win32.LONG) is
  360.   idx : Win32.LONG;
  361. begin
  362.   for idx in 0 .. 2 loop
  363.     XForm.xForm (idx,0) := Xform.xForm (idx,0) * xScale;
  364.     XForm.xForm (idx,1) := Xform.xForm (idx,1) * yScale;
  365.   end loop;
  366. end XformScale;
  367.  
  368.  
  369. procedure XFormTrans(XForm : in out MYXFORM;
  370.                      xTrans : Win32.LONG;
  371.                      yTrans : Win32.LONG) is
  372. begin
  373.   XForm.xForm (2,0) := XForm.xForm (2,0) + xTrans;
  374.   XForm.xForm (2,1) := XForm.xForm (2,1) + yTrans;
  375. end XFormTrans;
  376.  
  377.  
  378. procedure XFormPoint (XForm : MYXFORM;
  379.                       Point : in out Win32.WinDef.POINT) is
  380.   x,y : Win32.LONG;
  381. begin
  382.   x := (XForm.xForm(0,0) * Point.x) + (XForm.xForm(1,0) * Point.y) +  
  383.         XForm.xForm(2,0);
  384.   y := (XForm.xForm(0,1) * Point.x) + (XForm.xForm(1,1) * Point.y) + 
  385.         XForm.xForm(2,1);
  386.   Point.x := x;
  387.   Point.y := y;
  388. end XFormPoint;
  389.  
  390. -- ** -------------------------------
  391. -- ** -------------------------------
  392. -- ** -------------------------------
  393.  
  394. function ballCreate (hWnd_p  : Win32.WinDef.HWND;
  395.                      nWidth  : Win32.LONG;
  396.                      nHeight : Win32.LONG;
  397.                      crColor : Win32.WinDef.COLORREF) return 
  398.                                                       Win32.Winnt.HANDLE is
  399.   hBall : Win32.Windef.HLOCAL;
  400.   pbd   : PBALLDATA;
  401.   mem_ptr : Win32.LPVOID;
  402. begin
  403.   hBall := Win32.WinBase.LocalAlloc (Win32.WinBase.LHND, (BALLDATA'size / 8));
  404.   if hBall /= System.Null_Address then
  405.     mem_ptr := Win32.WinBase.LocalLock (hBall);
  406.     if mem_ptr /= System.Null_Address then 
  407.       pbd := LPVOID_TO_PBALLDATA (mem_ptr);
  408.       pbd.hWnd         := hWnd_p;
  409.       pbd.nWidth       := nWidth;
  410.       pbd.nHeight      := nHeight;
  411.       pbd.xDirection   := 0;
  412.       pbd.yDirection   := 0;
  413.       pbd.bNewPosition := Win32.FALSE;
  414.       pbd.xPosition    := 0;
  415.       pbd.yPosition    := 0;
  416.       pbd.crColor      := crColor;
  417.       XFormClear(pbd.xForm);
  418.  
  419.       bResult := Win32.WinBase.LocalUnlock (hBall);
  420.       return Win32.Winnt.HANDLE (hBall);
  421.     end if;
  422.     hlResult := Win32.WinBase.LocalFree (hBall);
  423.   end if;
  424.   return System.Null_Address;
  425. end ballCreate;
  426.  
  427.  
  428. function ballDestroy (hBall : Win32.Winnt.HANDLE) return Win32.BOOL is
  429. begin
  430.   if Win32.WinBase.LocalFree (Win32.Windef.HLOCAL (hBall)) 
  431.       /= System.Null_Address then
  432.     return Win32.FALSE;
  433.   else
  434.     return Win32.True;
  435.   end if;
  436. end ballDestroy;
  437.  
  438.  
  439. procedure ballBounce (hBall : Win32.Winnt.HANDLE) is
  440.   pbd            : PBALLDATA;
  441.   pbd_ptr        : Win32.LPVOID;
  442.   hDC_p          : Win32.WinDef.HDC;
  443.   hBrush_p       : Win32.WinDef.HBRUSH;
  444.   hTmp,hOld,hNew : Win32.WinDef.HRGN;
  445. begin
  446.   pbd_ptr := Win32.WinBase.LocalLock (Win32.Windef.HLOCAL (hBall));
  447.   if pbd_ptr /= System.Null_Address then 
  448.     pbd := LPVOID_TO_PBALLDATA (pbd_ptr);
  449.     -- /*
  450.     -- ** Create old ball object.
  451.     -- */
  452.     pOrg.x := 0;
  453.     pOrg.y := 0;
  454.     pExt.x := pbd.nWidth;
  455.     pExt.y := pbd.nHeight;
  456.     XFormPoint(pbd.xForm,pOrg);
  457.     XFormPoint(pbd.xForm,pExt);
  458.     hOld := Win32.WinGdi.CreateEllipticRgn(Win32.INT(pOrg.x),Win32.INT(pOrg.y),
  459.                                            Win32.INT(pExt.x),Win32.INT(pExt.y));
  460.  
  461.     -- /*
  462.     -- ** Create new ball object.
  463.     -- */
  464.     if pbd.bNewPosition = Win32.TRUE then
  465.       pbd.bNewPosition := Win32.FALSE;
  466.       XFormClear(pbd.xForm);
  467.       XFormTrans(pbd.xForm,pbd.xPosition,pbd.yPosition);
  468.     else
  469.       XFormTrans(pbd.xForm,pbd.xDirection,pbd.yDirection);
  470.     end if;
  471.  
  472.     pOrg.x := 0;
  473.     pOrg.y := 0;
  474.     pExt.x := pbd.nWidth;
  475.     pExt.y := pbd.nHeight;
  476.     XFormPoint(pbd.xForm,pOrg);
  477.     XFormPoint(pbd.xForm,pExt);
  478.     hNew := Win32.WinGdi.CreateEllipticRgn(Win32.INT(pOrg.x),Win32.INT(pOrg.y),
  479.                                            Win32.INT(pExt.x),Win32.INT(pExt.y));
  480.  
  481.     hDC_p := Win32.WinUser.GetDC (pbd.hWnd); 
  482.     if hDC_p /= System.Null_Address then
  483.       hTmp := Win32.WinGdi.CreateRectRgn(1,1,2,2);
  484.       iResult := Win32.WinGdi.CombineRgn(hTmp,hOld,hNew,Win32.WinGdi.RGN_DIFF);
  485.       bResult := Win32.WinGdi.FillRgn(hDC_p,hTmp,
  486.                                 Gdidemo_Util.GETCLASSBRUSH(pbd.hWnd));
  487.  
  488.       hBrush_p := Win32.WinGdi.CreateSolidBrush(pbd.crColor);
  489.       bResult := Win32.WinGdi.FillRgn(hDC_p,hNew,hBrush_p);
  490.       bResult := Win32.WinGdi.DeleteObject(Win32.Windef.HGDIOBJ (hBrush_p));
  491.  
  492.       iResult := Win32.WinUser.ReleaseDC(pbd.hWnd,hDC_p);
  493.  
  494.       bResult := Win32.WinGdi.DeleteObject(Win32.Windef.HGDIOBJ (hTmp));
  495.     end if;
  496.     bResult := Win32.WinGdi.DeleteObject(Win32.Windef.HGDIOBJ (hOld));
  497.     bResult := Win32.WinGdi.DeleteObject(Win32.Windef.HGDIOBJ (hNew));
  498.  
  499.     bResult := Win32.WinBase.LocalUnlock(Win32.Windef.HLOCAL (hBall));
  500.   end if;
  501. end ballBounce;
  502.  
  503.  
  504. procedure ballGetDimensions(hBall      : Win32.Winnt.HANDLE;
  505.                             pDimension : in out Win32.WinDef.POINT) is
  506.   pbd : PBALLDATA;
  507.   bOK : Win32.BOOL;
  508.   pbd_pvoid : Win32.LPVOID;
  509. begin
  510.   bOK := Win32.FALSE;
  511.   pbd_pvoid := Win32.WinBase.LocalLock (Win32.Windef.HLOCAL (hBall));
  512.   if pbd_pvoid /= System.Null_Address then
  513.     pbd := LPVOID_TO_PBALLDATA (pbd_pvoid);
  514.     pDimension.x := pbd.nWidth;
  515.     pDimension.y := pbd.nHeight;
  516.  
  517.     bOK := Win32.TRUE;
  518.     bResult := Win32.WinBase.LocalUnlock (Win32.Windef.HLOCAL (hBall));
  519.   end if;
  520. end ballGetDimensions;
  521.  
  522.  
  523. function ballSetDimensions (hBall   : Win32.Winnt.HANDLE;
  524.                             nWidth  : Win32.LONG;
  525.                             nHeight : Win32.LONG) return Win32.BOOL is
  526.   pbd : PBALLDATA;
  527.   bOK : Win32.BOOL;
  528.   pbd_pvoid : Win32.LPVOID;
  529. begin
  530.   bOK := Win32.FALSE;
  531.   pbd_pvoid := Win32.WinBase.LocalLock (Win32.Windef.HLOCAL (hBall));
  532.   if pbd_pvoid /= System.Null_Address then 
  533.     pbd := LPVOID_TO_PBALLDATA (pbd_pvoid);
  534.     pbd.nWidth  := nWidth;
  535.     pbd.nHeight := nHeight;
  536.  
  537.     bOK := Win32.TRUE;
  538.     bResult := Win32.WinBase.LocalUnlock (Win32.Windef.HLOCAL (hBall));
  539.   end if;
  540.   return bOK;
  541. end ballSetDimensions; 
  542.  
  543.  
  544. procedure ballGetDirection (hBall      : Win32.Winnt.HANDLE;
  545.                             pDirection : in out Win32.WinDef.POINT)  is
  546.   pbd : PBALLDATA;
  547.   bOK : Win32.BOOL;
  548.   pbd_pvoid : Win32.LPVOID;
  549. begin
  550.   bOK := Win32.FALSE;
  551.   pbd_pvoid := Win32.WinBase.LocalLock (Win32.Windef.HLOCAL (hBall));
  552.   if pbd_pvoid /= System.Null_Address then 
  553.     pbd := LPVOID_TO_PBALLDATA (pbd_pvoid);
  554.     pDirection.x := pbd.xDirection;
  555.     pDirection.y := pbd.yDirection;
  556.  
  557.     bOK := Win32.TRUE;
  558.     bResult := Win32.WinBase.LocalUnlock (Win32.Windef.HLOCAL (hBall));
  559.   end if;
  560. end ballGetDirection;
  561.  
  562.  
  563. procedure ballSetDirection (hBall      : Win32.Winnt.HANDLE;
  564.                             xDirection : Win32.LONG;
  565.                             yDirection : Win32.LONG) is
  566.   pbd : PBALLDATA;
  567.   bOK : Win32.BOOL;
  568.   pbd_pvoid : Win32.LPVOID;
  569. begin
  570.   bOK := Win32.FALSE;
  571.   pbd_pvoid := Win32.WinBase.LocalLock (Win32.Windef.HLOCAL (hBall));
  572.   if pbd_pvoid /= System.Null_Address then 
  573.     pbd := LPVOID_TO_PBALLDATA (pbd_pvoid);
  574.     pbd.xDirection := xDirection;
  575.     pbd.yDirection := yDirection;
  576.  
  577.     bOK := Win32.TRUE;
  578.     bResult := Win32.WinBase.LocalUnlock (Win32.Windef.HLOCAL (hBall));
  579.   end if;
  580. end ballSetDirection; 
  581.  
  582.  
  583. procedure ballGetPosition (hBall     : Win32.Winnt.HANDLE;
  584.                            pPosition : in out Win32.WinDef.POINT)  is
  585.   pbd  : PBALLDATA;
  586.   bOK  : Win32.BOOL;
  587.   pbd_pvoid : Win32.LPVOID;
  588. begin
  589.   bOK := Win32.FALSE;
  590.   pbd_pvoid := Win32.WinBase.LocalLock (Win32.Windef.HLOCAL (hBall));
  591.   if pbd_pvoid /= System.Null_Address then 
  592.     pbd := LPVOID_TO_PBALLDATA (pbd_pvoid);
  593.     pOrg2.x := 0;
  594.     pOrg2.y := 0;
  595.     XFormPoint(pbd.xForm,pOrg2);
  596.  
  597.     pPosition.x := pOrg2.x;
  598.     pPosition.y := pOrg2.y;
  599.  
  600.     bOK := Win32.TRUE;
  601.     bResult := Win32.WinBase.LocalUnlock(Win32.Windef.HLOCAL (hBall));
  602.   end if;
  603. end ballGetPosition; 
  604.  
  605.  
  606. procedure ballSetPosition (hBall : Win32.Winnt.HANDLE;
  607.                            x     : Win32.LONG;
  608.                            y     : Win32.LONG) is 
  609.   pbd : PBALLDATA;
  610.   bOK : Win32.BOOL;
  611.   pbd_pvoid : Win32.LPVOID;
  612. begin
  613.   bOK := Win32.FALSE;
  614.   pbd_pvoid := Win32.WinBase.LocalLock (Win32.Windef.HLOCAL (hBall));
  615.   if pbd_pvoid /= System.Null_Address then 
  616.     pbd := LPVOID_TO_PBALLDATA (pbd_pvoid);
  617.     pbd.bNewPosition := Win32.TRUE;
  618.     pbd.xPosition    := x;
  619.     pbd.yPosition    := y;
  620.  
  621.     bOK := Win32.TRUE;
  622.     bResult := Win32.WinBase.LocalUnlock(Win32.Windef.HLOCAL (hBall));
  623.   end if;
  624.  
  625. end ballSetPosition;
  626.  
  627. -------------------------------------------------------------------------------
  628. --
  629. -- THIS FILE AND ANY ASSOCIATED DOCUMENTATION IS PROVIDED "AS IS" WITHOUT 
  630. -- WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT 
  631. -- LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR 
  632. -- A PARTICULAR PURPOSE.  The user assumes the entire risk as to the accuracy 
  633. -- and the use of this file.  This file may be used only by licensees of 
  634. -- Microsoft Corporation's WIN32 Software Development Kit in accordance with 
  635. -- the terms of the licensee's End-User License Agreement for Microsoft 
  636. -- Software for the WIN32 Development Kit.
  637. --
  638. -- Copyright (c) Intermetrics, Inc. 1995
  639. -- Portions (c) 1985-1994 Microsoft Corporation with permission.
  640. -- Microsoft is a registered trademark and Windows and Windows NT are 
  641. -- trademarks of Microsoft Corporation.
  642. --
  643. -------------------------------------------------------------------------------
  644.  
  645. end Bounce;
  646.