home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / FRECLIEN / GUIBALL.H < prev    next >
C/C++ Source or Header  |  1997-01-05  |  4KB  |  118 lines

  1. /*+==========================================================================
  2.   File:      GUIBALL.H
  3.  
  4.   Summary:   Include file for the CGuiBall C++ class. A GuiBall is a C++
  5.              object that uses three independent worker threads to display
  6.              a moving and bouncing ball in the client area of a designated
  7.              window.  It is anchored to the Windows GUI (Graphical User
  8.              Interface) environment. This GuiBall object continuously
  9.              paints a ball image based on data it obtains from a virtual
  10.              ball object. This virtual ball object is instantiated as a
  11.              COM object (a COBall) in a separate In-process server,
  12.              FRESERVE.
  13.  
  14.              GuiBall launches three threads which all continuously and
  15.              asynchronously command the ball to move. GuiBall itself
  16.              provides methods to initialize the GuiBall, paint the ball
  17.              image, and restart the motion.
  18.  
  19.              For a comprehensive tutorial code tour of GUIBALL's contents
  20.              and offerings see the tutorial FRECLIEN.HTM file. For more
  21.              specific technical details on the internal workings see the
  22.              comments dispersed throughout the GUIBALL source code.
  23.  
  24.   Classes:   CThreadInitData, CGuiBall
  25.  
  26.   Origin:    4-5-96: atrent - Created for ActiveX Tutorial Code Samples.
  27. ----------------------------------------------------------------------------
  28.   This file is part of the Microsoft ActiveX Tutorial Code Samples.
  29.  
  30.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  31.  
  32.   This source code is intended only as a supplement to Microsoft
  33.   Development Tools and/or on-line documentation.  See these other
  34.   materials for detailed information regarding Microsoft code samples.
  35.  
  36.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  37.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  38.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  39.   PARTICULAR PURPOSE.
  40. ==========================================================================+*/
  41.  
  42. #if !defined(GUIBALL_H)
  43. #define GUIBALL_H
  44.  
  45. #if defined(__cplusplus)
  46.  
  47.  
  48. // Here are constants for the delays in millisecons that control
  49. // the incremental motion of the ball and how often a snapshot of
  50. // the ball image is painted.
  51. enum { BALL_PAINT_DELAY  = 44, BALL_MOVE_DELAY = 99 };
  52. // enum { BALL_PAINT_DELAY  = 55, BALL_MOVE_DELAY = 88 };
  53. // enum { BALL_PAINT_DELAY  = 22, BALL_MOVE_DELAY = 55 };
  54.  
  55. // A small utility struct providing an encapsulation of data needed when
  56. // worker threads are initialized.
  57. struct CThreadInitData
  58. {
  59.   HWND     m_hWnd;
  60.   IBall*   m_pIBall;
  61.   DWORD    m_nDelay;
  62. };
  63.  
  64.  
  65. /*C+C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C
  66.   Class:    CGuiBall
  67.  
  68.   Summary:  Class to encapsulate the displayable Graphical User
  69.             Interface GUI Ball object.
  70.  
  71.   Methods:  CGuiBall
  72.               Constructor.
  73.             ~CGuiBall
  74.               Destructor.
  75.             BOOL Init(HWND hWnd);
  76.               Initialize the GuiBall.
  77.             void PaintBall(void);
  78.               Paint one image of the Ball.
  79.             void Restart(void);
  80.               Restart the process including clear window, move ball to
  81.               start position, restart motion.
  82.             void PaintWin(void);
  83.               Repaint the window but don't restart motion.
  84. C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C-C*/
  85. class CGuiBall
  86. {
  87.   private:
  88.     HWND     m_hWnd;
  89.     IBall*   m_pIBall;
  90.     COLORREF m_crColor;
  91.  
  92.     // Pointers to thread init data structures.
  93.     CThreadInitData m_BallThreadData1;
  94.     CThreadInitData m_BallThreadData2;
  95.     CThreadInitData m_BallThreadData3;
  96.  
  97.   public:
  98.     // Some member variables to store thread ids.
  99.     DWORD m_dwBallThread1;
  100.     DWORD m_dwBallThread2;
  101.     DWORD m_dwBallThread3;
  102.  
  103.     // An array of handles to the ball threads.
  104.     HANDLE m_hBallThreads[3];
  105.  
  106.     CGuiBall(void);
  107.     ~CGuiBall(void);
  108.     BOOL Init(HWND hWnd);
  109.     void PaintBall(void);
  110.     void Restart(void);
  111.     void PaintWin(void);
  112. };
  113.  
  114.  
  115. #endif // __cplusplus
  116.  
  117. #endif
  118.