home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / tutsamp / freclien / guiball.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-09  |  4.0 KB  |  116 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:    9-8-97: atrent - Created for COM Tutorial Samples. [Revised]
  27. ----------------------------------------------------------------------------
  28.   This file is part of the Microsoft COM 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  = 33, BALL_MOVE_DELAY = 222 };
  52.  
  53. // A small utility struct providing an encapsulation of data needed when
  54. // worker threads are initialized.
  55. struct CThreadInitData
  56. {
  57.   HWND     m_hWnd;
  58.   IBall*   m_pIBall;
  59.   DWORD    m_nDelay;
  60. };
  61.  
  62.  
  63. /*C+C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C
  64.   Class:    CGuiBall
  65.  
  66.   Summary:  Class to encapsulate the displayable Graphical User
  67.             Interface GUI Ball object.
  68.  
  69.   Methods:  CGuiBall
  70.               Constructor.
  71.             ~CGuiBall
  72.               Destructor.
  73.             BOOL Init(HWND hWnd);
  74.               Initialize the GuiBall.
  75.             void PaintBall(void);
  76.               Paint one image of the Ball.
  77.             void Restart(void);
  78.               Restart the process including clear window, move ball to
  79.               start position, restart motion.
  80.             void PaintWin(void);
  81.               Repaint the window but don't restart motion.
  82. C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C-C*/
  83. class CGuiBall
  84. {
  85.   private:
  86.     HWND     m_hWnd;
  87.     IBall*   m_pIBall;
  88.     COLORREF m_crColor;
  89.  
  90.     // Pointers to thread init data structures.
  91.     CThreadInitData m_BallThreadData1;
  92.     CThreadInitData m_BallThreadData2;
  93.     CThreadInitData m_BallThreadData3;
  94.  
  95.   public:
  96.     // Some member variables to store thread ids.
  97.     DWORD m_dwBallThread1;
  98.     DWORD m_dwBallThread2;
  99.     DWORD m_dwBallThread3;
  100.  
  101.     // An array of handles to the ball threads.
  102.     HANDLE m_hBallThreads[3];
  103.  
  104.     CGuiBall(void);
  105.     ~CGuiBall(void);
  106.     BOOL Init(HWND hWnd);
  107.     void PaintBall(void);
  108.     void Restart(void);
  109.     void PaintWin(void);
  110. };
  111.  
  112.  
  113. #endif // __cplusplus
  114.  
  115. #endif
  116.